I have a generic class that extends another generic class. They are all @MappedSuperclass . Thus, they do not have their own table in the database. They are also abstract, so they have no objects. This is just a skeleton for my @Entity entities
My inheritance structure:
Generic -> GenericDictionary -> GenericHierarchicalDictionary -> Unit
Where Unit @Entity class and have objects.
@Entity public class Unit extends GenericHierarchicalDictionary<Unit> {}
A single object has a hierarchical structure , which means that Entity is related to itself, but for this I use an abstract class ( @MappedSuperclass ), so I would like to define it dynamically in this abstract class:
My GenericHierarchicalDictionary:
@MappedSuperclass public abstract class GenericHierarchicalDictionary<T extends Generic<T>> extends GenericDictionary<T> { @Required @ManyToOne(targetEntity = GenericHierarchicalDictionary.class, fetch=FetchType.LAZY, cascade = {CascadeType.ALL}) @JoinColumn(name="parent_id") public GenericHierarchicalDictionary<T> parent;
But id dosnt works. I get an error message:
play.api.UnexpectedException: Unexpected exception[PersistenceException: [PersistenceUnit: defaultPersistenceUnit] Unable to configure EntityManagerFactory] at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:148) ~[play_2.10.jar:2.2.4] at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:112) ~[play_2.10.jar:2.2.4] at scala.Option.map(Option.scala:145) ~[scala-library.jar:na] at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:112) ~[play_2.10.jar:2.2.4] at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:110) ~[play_2.10.jar:2.2.4] at scala.util.Success.flatMap(Try.scala:200) ~[scala-library.jar:na] Caused by: javax.persistence.PersistenceException: [PersistenceUnit: defaultPersistenceUnit] Unable to configure EntityManagerFactory at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:378) ~[hibernate-entitymanager-3.6.9.Final.jar:3.6.9.Final] at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56) ~[hibernate-entitymanager-3.6.9.Final.jar:3.6.9.Final] at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63) ~[hibernate-jpa-2.0-api.jar:1.0.1.Final] at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47) ~[hibernate-jpa-2.0-api.jar:1.0.1.Final] at play.db.jpa.JPAPlugin.onStart(JPAPlugin.java:35) ~[play-java-jpa_2.10.jar:2.2.4] at play.api.Play$$anonfun$start$1$$anonfun$apply$mcV$sp$1.apply(Play.scala:88) ~[play_2.10.jar:2.2.4] Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on models.Unit.parent references an unknown entity: models.GenericHierarchicalDictionary at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:107) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final] at org.hibernate.cfg.Configuration.processEndOfQueue(Configuration.java:1580) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final] at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1503) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final] at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1419) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final] at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1375) ~[hibernate-core-3.6.9.Final.jar:3.6.9.Final] at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1519) ~[hibernate-entitymanager-3.6.9.Final.jar:3.6.9.Final]
If I get this error, I have to assign targetEntity to a java class with @Entity annotation, but that is not what I would like to have.
I want @ManyToOne targetEntity to be declared dynamically from an Entity context.
How can I achieve this? Please help me.