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 run mvn 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.