jpa - Hibernate: AnnotationException: Unknown mappedBy in ... referenced property unknown on reverse (mappedBy), bi-directional @OneToOne associations -


i have following simple design:

valid xhtml http://www.kawoolutions.com/media/persons-roles-reduced.png

that's workaround non-disjoint inheritance jpa doesn't support. persons can exist own, there can optionally single player entity, single coach entity, or both entities complete logic.

here rather easy-to-understand jpa 2.0 mappings (note @id forward associations):

@entity @table(name = "persons") public class person implements serializable {     @id     @column(name = "id")     private integer id;      @column(name = "first_name")     private string firstname;      @column(name = "last_name")     private string lastname;      @onetoone(mappedby = "person")     private coach coach = null;      @onetoone(mappedby = "person")     private player player = null;      ... }  @entity @table(name = "players") public class player implements serializable {     @column(name = "registration_nbr")     private string registrationnbr = null;      @id     @onetoone     @joincolumn(name = "id")     private person person = null;      ... }  @entity @table(name = "coaches") public class coach implements serializable {     @column(name = "license_nbr")     private string licensenbr = null;      @id     @onetoone     @joincolumn(name = "id")     private person person = null;      ... } 

the player , coach entity classes identical.

the problem here 2 bi-directional associations (mappedby). these mappings work eclipselink, hibernate somehow freaks out annotationexception:

exception in thread "main" javax.persistence.persistenceexception: [persistenceunit: persons] unable configure entitymanagerfactory     @ org.hibernate.ejb.ejb3configuration.configure(ejb3configuration.java:374)     @ org.hibernate.ejb.hibernatepersistence.createentitymanagerfactory(hibernatepersistence.java:56)     @ javax.persistence.persistence.createentitymanagerfactory(persistence.java:48)     @ javax.persistence.persistence.createentitymanagerfactory(persistence.java:32)     @ tld.persons.main.main(main.java:32) caused by: org.hibernate.annotationexception: unknown mappedby in: tld.persons.model.person.coach, referenced property unknown: tld.persons.model.coach.person     @ org.hibernate.cfg.onetoonesecondpass.dosecondpass(onetoonesecondpass.java:159)     @ org.hibernate.cfg.configuration.originalsecondpasscompile(configuration.java:1686)     @ org.hibernate.cfg.configuration.secondpasscompile(configuration.java:1393)     @ org.hibernate.cfg.configuration.buildmappings(configuration.java:1345)     @ org.hibernate.ejb.ejb3configuration.buildmappings(ejb3configuration.java:1477)     @ org.hibernate.ejb.eventlistenerconfigurator.configure(eventlistenerconfigurator.java:193)     @ org.hibernate.ejb.ejb3configuration.configure(ejb3configuration.java:1096)     @ org.hibernate.ejb.ejb3configuration.configure(ejb3configuration.java:278)     @ org.hibernate.ejb.ejb3configuration.configure(ejb3configuration.java:362)     ... 4 more 

when switching old-school jpa 1.0 mappings runs fine again. hibernate somehow seems have problems above mappings.

i've looked @ soo many other problem reports, in fact forum @ hibernate.org filled similar unsolved problems, couldn't find clues why throws exception.

to me appears hibernate bug. can confirm this? (note i'm using hibernate 3.6)

the issue can encountered if forget declare entity class in persistence.xml.


Comments