« Return to Thread: Entity relationship issue

Re: Entity relationship issue

by Guy Pelletier :: Rate this Message:

Reply to Author | View in Thread

Kevin,

What does your model look like exactly to get this? Are you purposely trying
to use a uni-directional 1-M using a JoinTable? Because what I am seeing
would indicate that there is no mappedBy value specified on the 1-M.

Cheers,
Guy

----- Original Message -----
From: "khaskett" <khaskett@...>
To: <eclipselink-users@...>
Sent: Wednesday, December 03, 2008 8:49 AM
Subject: Re: [eclipselink-users] Entity relationship issue


>
> I added that and I still get this error -
> [IBM][SQLServer JDBC Driver][SQLServer]Invalid object name
> 'CPUSER_CP_MSG'.
> Call: SELECT t1.MSG_ID, t1.MSG_TEXT, t1.CPUSER_paramUserID FROM
> CPUSER_CP_MSG t0, CP_MSG t1 WHERE ((t0.CpUser_paramUserID = ?) AND
> (t1.MSG_ID = t0.messages_MSG_ID))
> bind => [USER123       ]
>
> I guess what I thought would happen is this call
> SELECT t1.MSG_ID, t1.MSG_TEXT, t1.CPUSER_paramUserID FROM CPUSER_CP_MSG
> t0,
> CP_MSG t1 WHERE t1.USER_ID = ?
>
> Thanks for reply.
> Kevin
>
>
> Tim Hollosy wrote:
>>
>> You forgot the mappedBy attribute in your @ManyToOne annotation it
>> should be @ManyToOne(fetch = FetchType.LAZY,mappedBy="messages")
>>
>> You might try to generate your Entities using the Dali JPA Tools in
>> Eclipse to see the proper way to do these mappings.
>>
>> ./tch
>>
>>
>>
>> On Tue, Dec 2, 2008 at 11:59 PM, khaskett <khaskett@...> wrote:
>>>
>>> I added the @ManyToOne and i still get the same error -
>>>
>>> public class CpUser extends BaseDomain {
>>> ....
>>>    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY,
>>> mappedBy
>>> =
>>> "cpUser")
>>>    @JoinColumn(referencedColumnName = "USER_ID")
>>>    public Set<CpMsg> getMessages() {
>>>        return messages;
>>>    }
>>>
>>> public class CpMsg extends BaseDomain {
>>> ....
>>>    @ManyToOne(fetch = FetchType.LAZY)
>>>        public CpUser getCpUser() {
>>>                return this.cpUser;
>>>        }
>>>
>>> Thanks for the reply.
>>>
>>>
>>> Tim Hollosy wrote:
>>>>
>>>> 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@...> 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@...
>>>>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>>>>>
>>>> _______________________________________________
>>>> eclipselink-users mailing list
>>>> eclipselink-users@...
>>>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>>>>
>>>>
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Entity-relationship-issue-tp20803337p20806849.html
>>> Sent from the EclipseLink - Users mailing list archive at Nabble.com.
>>>
>>> _______________________________________________
>>> eclipselink-users mailing list
>>> eclipselink-users@...
>>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>>>
>> _______________________________________________
>> eclipselink-users mailing list
>> eclipselink-users@...
>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>>
>>
>
> --
> View this message in context:
> http://www.nabble.com/Entity-relationship-issue-tp20803337p20813256.html
> Sent from the EclipseLink - Users mailing list archive at Nabble.com.
>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@...
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>

_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

 « Return to Thread: Entity relationship issue