I am working against a legacy database with two tables that look something like this...
Code:
Two tables:
Detail Criteria
---------------------------------
*name *cri_id
*grp_id *grp_id
cri_id *seqnum
* Fields marked with an asterisk are PKs
Note that this technically could be a ManyToMany mapping (a given detail obviously links to multiple criteria since we're not joining against the seqnum column. However, the same criteria can also be pointed to by multiple detail records. But, since there's no middle join table so this isn't really a correct ManyToMany mapping (I have to work with what I'm given).
Anyway, I have tried to map this in Hibernate like so...
Code:
public class Detail {
...
@OneToMany
@JoinColumns({
@JoinColumn(name = "cri_id", referencedColumnName = "cri_id", insertable = false, updatable = false),
@JoinColumn(name = "grp_id", referencedColumnName = "grp_id", insertable = false, updatable = false)
// Note that we're NOT joining on the seqnum column also, here ---
})
@OrderBy("sequenceNumber ASC")
private List<Criteria> criteria = Lists.newArrayList();
@Column(name = "cri_id")
private String criteriaId;
...
}
This gives a null pointer exception during initialization in the Hibernate code...
Code:
java.lang.NullPointerException
at org.hibernate.cfg.annotations.CollectionBinder.bindCollectionSecondPass(CollectionBinder.java:1456)
at org.hibernate.cfg.annotations.CollectionBinder.bindOneToManySecondPass(CollectionBinder.java:864)
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:779)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:728)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:70)
at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1695)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1424)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)
...
If I remove the above mapping (or simply mark it as @Transient) Hibernate initializes fine. I realize this is kind of a borked table structure so is there a better method to performing this mapping or is this a Hibernate limitation due to the odd mapping?