2 Replies Latest reply on Nov 18, 2007 5:47 PM by Andy Peel

    Problems mixing descriptors and annotations?

    Andy Peel Newbie

      I have an entity, Foo, that has one-to-many FooChild children. This relationship is mapped via the OneToMany annotation. FooChild's properties are also mapped via annotation.

      Foo and FooChild deploy fine, until I add an entity listener to Foo. Unfortunately I have to use a deployment descriptor (orm.xml) to add the entity listener - to use an annotation would add a circular dependency to our Maven module structure :(

      <entity class="com.acme.Foo">
       <entity-listeners>
       <entity-listener class="com.acme.FooListener">
       <post-persist method-name="changeFoo" />
       <post-update method-name="changeFoo" />
       </entity-listener>
       </entity-listeners>
       </entity>



      This works on the whole, but for entities that have OneToMany children annotation, I get this exception:


      javax.persistence.PersistenceException: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com.acme.fooChildren[com.acme.FooChild]
       at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:252)
       at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:120)
       at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
      
      [snipped]
      
      Caused by: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com.acme.fooChildren[com.acme.FooChild]
       at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:1016)
       at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:567)
       at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:508)
       at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:43)
       at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1130)
       at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:296)
       at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
       at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1233)
       at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:154)
       at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:869)
       at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:183)
       at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:240)
       ... 19 more
      



      It *looks* like adding the descriptor on Foo is stopping the annotations in FooChild from being picked up.

      The annotations in FooChild are property rather than field, and my orm.xml contains the line:

      <access>PROPERTY</access>




      I could understand it not working if the descriptor didn't contain this line as it would presumably default to field and expect to find field-level annotations on FooChild but fail as they were property-based.


      Am I doing something wrong? I'm using JBoss 4.2.0GA.