Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » Using @ManyToOne with a @JoinTable
Using @ManyToOne with a @JoinTable [message #488971] Wed, 30 September 2009 19:56 Go to next message
Eclipse UserFriend
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 09:39 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Using @ManyToOne with a @JoinTable [message #489184 is a reply to message #489094] Thu, 01 October 2009 14:15 Go to previous message
Eclipse UserFriend
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: Wed Jul 23 17:17:50 EDT 2025

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

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

Back to the top