-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Problems mixing descriptors and annotations?
PostPosted: Fri Nov 16, 2007 11:52 am 
Beginner
Beginner

Joined: Tue Sep 30, 2003 10:09 am
Posts: 34
Location: London, UK
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 :(

Code:
<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:


Code:
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:

Code:
   <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.

Thanks,


Andy.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 19, 2007 9:15 am 
Regular
Regular

Joined: Thu Oct 13, 2005 4:19 am
Posts: 98
Have you marked FooChild as an entity?
either:
<entity class="com.acme.FooChild">
or
@Entity public class FooChild

_________________
http://www.ohloh.net/accounts/ge0ffrey


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 19, 2007 11:00 am 
Beginner
Beginner

Joined: Tue Sep 30, 2003 10:09 am
Posts: 34
Location: London, UK
It does, yes. Before I add the deployment descriptor, both Foo and FooChild deploy fine. It's only when I add the entity listener to Foo via orm.xml that they fail to deploy.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 28, 2008 6:28 am 
Beginner
Beginner

Joined: Tue Sep 30, 2003 10:09 am
Posts: 34
Location: London, UK
Turns out that it was fixed by putting the entity listener descriptor into a separate XML file and importing it into our persistence.xml using the <mapping-file> element.

It really didn't like being in orm.xml...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 20, 2008 2:36 pm 
Newbie

Joined: Thu Mar 20, 2008 10:39 am
Posts: 4
This post helped solving my issue..


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.