I have a ManyToMany Association, and on one side I'd like to collect related elements by a Map... but I have same problems declaring the map key (it should be simple the identifier of the collected entity):
Following the java.persistence specification I should write samething like:
@ManyToMany(
targetEntity=Target.class
)
@MapKey(
name="id"
)
@JoinTable(
name="ASSOCIATION_TABLE",
joinColumns={@JoinColumn(name="owner_id")},
inverseJoinColumns={@JoinColumn(name="tagret_id")}
)
public Map getMapOfTarget() {
return ..
}
But this seams not to work with hibernate... there's same SQL grammar errors in the generated sql
Then I try by the hibernate secifics annotations org.hibernate.annotations.MapKey and org.hibernate.annotations.MapKeyManyToMany but I can't understand how they work... I tried puting the name of join colum of ASSOCIATION TABLE or id colum of terget TABLE but I allways get a ...
Caused by: java.lang.NullPointerException
at org.hibernate.cfg.annotations.MapBinder.bindKeyFromAssociationTable(MapBinder.java:109)
at org.hibernate.cfg.annotations.MapBinder.access$000(MapBinder.java:55)
at org.hibernate.cfg.annotations.MapBinder$1.secondPass(MapBinder.java:78)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:35)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1049)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:302)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1205)
at it.prainf.utils.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:43)
... 126 more
Sameone has same idea?
TY
|