After having discovered how to solve my problem with @MapKeyManyToMany, I found a new odd one :
since I'm using @MapKeyManyToMany (see example in the previous post), I can't use @MapKey (mutually exclusive).
This seem to work fine as long as I run the program within Eclipse. When I'm launching it outside Eclipse, I get the following error :
Exception in thread "main" java.lang.ExceptionInInitializerError
at myproject.main.Application.main(Application.java:270)
Caused by: javax.persistence.PersistenceException: org.hibernate.AnnotationException: A Map must declare a @MapKey element
at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:188)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:110)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:37)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:27)
at com.eurocopter.cepe.lot2.bdd.SQL.DAOFactoryBDD.<clinit>(DAOFactoryBDD.java:39)
... 1 more
Caused by: org.hibernate.AnnotationException: A Map must declare a @MapKey element
at org.hibernate.cfg.annotations.MapBinder.bindKeyFromAssociationTable(MapBinder.java:63)
at org.hibernate.cfg.annotations.MapBinder.access$000(MapBinder.java:32)
at org.hibernate.cfg.annotations.MapBinder$1.secondPass(MapBinder.java:55)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:35)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1016)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:244)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1001)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:840)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:161)
at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:624)
at org.hibernate.ejb.Ejb3Configuration.createFactory(Ejb3Configuration.java:126)
at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:180)
... 5 more
Is this a bug ? Why does Hibernate ask for a MapKey when a MapKeyManyToMany is defined ? Or is it the JPA spec that requires that ?
My annotation is like this :
Quote:
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name = "CouleurAdaptateur", joinColumns = { @JoinColumn(name = "Id_GestionConfigBanc") }, inverseJoinColumns = { @JoinColumn(name = "Id_Def_Adaptateur") })
@MapKeyManyToMany(joinColumns = @JoinColumn(name = "CodeCouleur", unique = false))
private Map<Couleur, TAdaptateur> listeAdaptateurs = null;
This is very strange that I get the error only outside Eclipse (running through a .bat file)
I am using
-Eclipse Version : 3.2.0 ID génération : M20060629-1905
-Hibernate Annotations Version: 3.2.0.CR3
-Hibernate Core version: 3.2.0.cr5
-Hibernate EntityManager Version: 3.2.0.CR3
and EJB3-persistence version :
Quote:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.5
Created-By: 1.5.0_06-b05 (Sun Microsystems Inc.)
Built-By: hibernate.org
Specification-Title: EJB 3.0
Specification-Version: public-draft
Specification-Vendor: Sun Microsystems, Inc.
Implementation-Title: EJB
Implementation-Version: public-draft March 22 2006
Implementation-Vendor: hibernate.org
Thanks for any help !