I have a strange issue with Hibernate 3.5 which I hope some one can help me with.
Context:
- A FAC has zero or more “core” SECT’s.
- A FAC has zero or more “related” SECT’s.
- A SECT has exactly one parent FAC.
I have a jointable called fac_sect, the table has the following columns:
fac_related_sect_id, sect_id, fac_core_sect_id
A SECT can be related to a parent FAC via the fac_core_sect_id column.
I have the following in my Sect entity class:
@ManyToOne
@JoinTable(name = "fac_sect", joinColumns = { @JoinColumn(name = "sect_id")},
inverseJoinColumns = { @JoinColumn(name = "fac_core_sect_id") })
public Fac getParentFac() {
return parentFac;
}
The Problem
This seems to work fine where in *fac_sect* for a particular *sect_id* there are 2 rows; one row mapping a to a *fac_core_sect_id* and a second row mapping to a *fac_related_sect_id*.
But getParentFac() returns null when in *fac_sect* the *sect_id* has more than one row for the *fac_related_sect_id*.
I don’t understand why this happens as my @JoinTable annotation seems to be specifying the correct join column and inverse join column. I’m not even asking Hibernate to include the *fac_related_sect_id* column in the join.
Hope that makes sense, I hope some one can help me 🙂
I’ve solved this by creating 2 new join tables, each with only two columns.