Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Using @ManyToOne with a @JoinTable
Using @ManyToOne with a @JoinTable [message #488971] Wed, 30 September 2009 23:56 Go to next message
Brendan Haverlock is currently offline Brendan HaverlockFriend
Messages: 46
Registered: July 2009
Member
Hello everyone,

I have a joiner table that basically allows me to have generic relationships between entities. However, instead of being @ManyToMany's, I am basically trying to do a parent/child relationship via this table. The @OneToMany works fine through this joiner table and I am able to populate the list of children in the parent entity. The thing that is giving me trouble is the @ManyToOne join back to the parent in the child table. My parent's reference to it's children is as follows:

@OneToMany(cascade = CascadeType.ALL)
@JoinTable(name = "relationship",
joinColumns = {@JoinColumn(name = "target_key")},
inverseJoinColumns = {@JoinColumn(name = "source_key")})
@MapKey(name="id")
private Map<String, Child> children;

Now what I am trying to do on the child is as follows:

@ManyToOne
@JoinTable(name = "relationship",
joinColumns = {@JoinColumn(name = "source_key")},
inverseJoinColumns = {@JoinColumn(name = "target_key")})
private Parent parent;

Now, what is happening is it is trying to select a key within the child that represents the key to the parent entity, however, that key is obviously not there because it needs to go to the joiner table to get that information.

Can anyone please give me some insight on how to do this properly? I would REALLY appreciate it.

Thank you!
-Brendan Haverlock




Re: Using @ManyToOne with a @JoinTable [message #489094 is a reply to message #488971] Thu, 01 October 2009 13:39 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

What version of EclipseLink are you using?

EclipseLink did not support JoinTable on a ManyToOne until recently in the 2.0 stream. Try using the latest 2.0 build.

See also,
http://en.wikibooks.org/wiki/Java_Persistence/OneToOne#Mappi ng_a_OneToOne_Using_a_Join_Table


James : Wiki : Book : Blog : Twitter
Re: Using @ManyToOne with a @JoinTable [message #489184 is a reply to message #489094] Thu, 01 October 2009 18:15 Go to previous message
Brendan Haverlock is currently offline Brendan HaverlockFriend
Messages: 46
Registered: July 2009
Member
Yea, I am using 1.2.0. I will give 2.0 a shot. I hope it's stable!

Thanks
Previous Topic:@NamedStoredProcedureQuery problem
Next Topic:v1.1+ attempts to INSERT a copy of unchanged data
Goto Forum:
  


Current Time: Fri Mar 29 00:03:16 GMT 2024

Powered by FUDForum. Page generated in 0.07211 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top