title: Hibernate error "unable to locate persister"
body: <p>I am trying to execute some Java with the Maven exec plugin, and am getting an error <code>Caused by: org.hibernate.UnknownEntityTypeException: Unable to locate persister: my.biz.CoolEntity</code>. 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.</p>
  
  <p>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.</p>
  
  <p><strong>Background</strong></p>
  
  <p>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 <code>my.biz.CoolEntity</code>.</p>
  
  <p>Normally, I build everything into a shaded JAR and run/deploy that, without any issues. </p>
  
  <p><strong>Hibernate issue</strong></p>
  
  <p>Recently, I began using Maven's <code>exec:java</code> goal, but am running into what on the surface is a Hibernate issue. when I run <code>mvn exec:java -DmainClass=my.biz.CoolEntity</code>, I get this error:</p>
  
  <pre><code>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.&lt;init&gt;(SessionImpl.java:2579) ~[hibernate-core-5.0.1.Final
  .jar:5.0.1.Final]
          at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.&lt;init&gt;(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] 
  </code></pre>
  
  <p><strong>Failed attempts</strong></p>
  
  <p>I tried making use of the exec plugin's <a href="https://stackoverflow.com/a/19199709/614660"><code>&lt;additionalClasspathElements&gt;</code></a> and <a href="https://stackoverflow.com/a/11711997/614660"><code>&lt;includePluginDependencies&gt;</code></a>. The first solution didn't result in any different, and the second resulted in a compile-time error.</p>
  
  <p><strong>Hacky fix</strong></p>
  
  <p>What ended up working for me was copying the compiled classes from Project B into Project A.</p>