Using @ManyToOne with a @JoinTable [message #488971] |
Wed, 30 September 2009 23:56 |
Brendan Haverlock 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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02934 seconds