Hibernate error "unable to locate persister"
When the entities are residing in a different jar, you have to include it in persistence.xml. <jar-file>entities-packaged.jar</jar-file>
. Different options are explained here
maxenglander
Mostly self-taught developer. Hooked on computing since my first exposure to Linux in high school. My first internships were developing medical devices for a research lab at Siemens. After entering the real world, I spent the first four years of my career working for ad- and marketing- tech companies. Now I'm developing mental wellness technology for a startup.
Updated on July 13, 2022Comments
-
maxenglander almost 2 years
I am trying to execute some Java with the Maven exec plugin, and am getting an error
Caused by: org.hibernate.UnknownEntityTypeException: Unable to locate persister: my.biz.CoolEntity
. I tried a number of failed solutions, before ultimately finding a hacky fix. Based on the hacky fix, I believe the issue to be a runtime classpath error.I am looking for an answer that will tell me how to address the problem without resorting to copying the needed files into place, as I do in the hacky fix.
Background
I have a Maven project "Project A" which has dependencies upon Hibernate 5.0.1.Final as well as another project "Project B". Project B contains my JPA entity classes, including
my.biz.CoolEntity
.Normally, I build everything into a shaded JAR and run/deploy that, without any issues.
Hibernate issue
Recently, I began using Maven's
exec:java
goal, but am running into what on the surface is a Hibernate issue. when I runmvn exec:java -DmainClass=my.biz.CoolEntity
, I get this error:Caused by: org.hibernate.UnknownEntityTypeException: Unable to locate persister: my.biz.CoolEntity at org.hibernate.internal.SessionFactoryImpl.locateEntityPersister(SessionFactoryImpl.java:792) ~[hibernate-core-5.0.1.Fi nal.jar:5.0.1.Final] at org.hibernate.internal.SessionImpl.locateEntityPersister(SessionImpl.java:2641) ~[hibernate-core-5.0.1.Final.jar:5.0.1 .Final] at org.hibernate.internal.SessionImpl.access$2500(SessionImpl.java:164) ~[hibernate-core-5.0.1.Final.jar:5.0.1.Final] at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.<init>(SessionImpl.java:2579) ~[hibernate-core-5.0.1.Final .jar:5.0.1.Final] at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.<init>(SessionImpl.java:2566) ~[hibernate-core-5.0.1.Final .jar:5.0.1.Final] at org.hibernate.internal.SessionImpl.byId(SessionImpl.java:1044) ~[hibernate-core-5.0.1.Final.jar:5.0.1.Final] at org.hibernate.internal.SessionImpl.get(SessionImpl.java:955) ~[hibernate-core-5.0.1.Final.jar:5.0.1.Final] at org.hibernate.jpa.spi.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:1075) ~[hibernate-entitymanager-5. 0.1.Final.jar:5.0.1.Final]
Failed attempts
I tried making use of the exec plugin's
<additionalClasspathElements>
and<includePluginDependencies>
. The first solution didn't result in any different, and the second resulted in a compile-time error.Hacky fix
What ended up working for me was copying the compiled classes from Project B into Project A.