[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[List Home]
|
Re: [eclipselink-users] Entity relationship issue
|
- From: "Tim Hollosy" <hollosyt@xxxxxxxxx>
- Date: Tue, 2 Dec 2008 19:38:11 -0500
- Delivered-to: eclipselink-users@eclipse.org
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=k9kzwW4nNtexm78gyanSlpbI60BfBsb5KQqLjUeA1wg=; b=jHcShxi1gSlhSEQgwrlEnQwms/2fStTbXd07hMvNDycCShZ6JukJDcnX0o3/b0FsX8 xNPd6Zm/K/VrG74Va8lIhhc6crqqDuxspGcYc1m8UgOR6+fWHAF2Vk5FCIEvuBknqscG 9E4BrogsYL6fgpIUVKvAyrNVgaece4Qy+ypX8=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=E4uzdFVknfE0n/Qx+hsjUPIb3ebcGZVt50vm8LxljNj79ojD9EEpUydAsyGvWcuInh I5HkQLxLru1PLY87N9UYM6/lKWXEamlkCxfGIf/xjWL/8PNqI2oFqf2sfRFmQ4H/HUOw NmsQbIA2soyC3QgOeGvv5U9vvZmokzJJ9rpqE=
It doesn't look like your relationship is defined in both entities. In
JPA you always need to make sure you do this. You need to have the
@ManyToOne annotation back in your CpMsg entity.
Check: http://en.wikibooks.org/wiki/Java_Persistence/OneToMany
for more info.
./tch
On Tue, Dec 2, 2008 at 6:20 PM, khaskett <khaskett@xxxxxxxxxxx> wrote:
>
> I am having an issue with creating a relationship between 2 entities, where
> the parent entity was created from a Stored Procedure. When I try to use the
> @OneToMany annotation it tries to join the two entities.
>
> @Entity
> public class CpUser extends BaseDomain {
>
> // Attributes
> @Id
> @Column(name = "paramUserID")
> private String userId;
>
> @Column(name = "paramInitials")
> private String initials;
>
> @Column(name = "paramFirstName")
> private String firstName;
>
> @Column(name = "paramLastName")
> private String lastName;
>
> .....
>
> /*
> * List of user messages
> */
> private Set<CpMsg> messages = new HashSet<CpMsg>(0);
>
> .....
> @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy =
> "userId")
> public Set<CpMsg> getMessages() {
> return messages;
> }
> } // End CpUser
>
> @Entity
> @Table(name = "CP_MSG")
> public class CpMsg extends BaseDomain {
>
> // Fields
> @Id
> @GeneratedValue(strategy = GenerationType.IDENTITY)
> @Column(name = "MSG_ID", unique = true, nullable = false, precision = 11,
> scale = 0)
> private Long msgId;
> @Column(name = "MSG_TEXT", nullable = false)
> private String msgText;
>
> private CpUser cpUser;
> ....
> public CpUser getCpUser() {
> return this.cpUser;
> }
> } //End CpMsg
>
> I removed some fields for brevity.
> When I try and get the messages for that user by calling getMessages() I get
> this in the logs -
> Call: SELECT t1.MSG_ID, t1.MSG_TEXT, t1.USER_ID FROM CPUSER_CP_MSG t0,
> CP_MSG t1 WHERE ((t0.CpUser_paramUserID = ?) AND (t1.MSG_ID =
> t0.messages_MSG_ID))
> bind => [USER123]
>
> And the error is that CPUSER_CP_MSG doesnt exist, which is correct.
>
> I guess I assumed it would just do a select on the child table passing in
> the value from the parent.
>
> Thanks in advance
>
> --
> View this message in context: http://www.nabble.com/Entity-relationship-issue-tp20803337p20803337.html
> Sent from the EclipseLink - Users mailing list archive at Nabble.com.
>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>