Not an entity - Hibernate



I am starting a project with play 2.6 using. I am annotating my entities with @Entity (from javax.persistence) and everything works fine on development. But after I run the “dist” task I get this error when I try to access the database

java.lang.IllegalArgumentException: Not an entity

If I add the entity as package.entity to my persistence.xml the error goes away, but I want to know why is this necessary or if it is some error in my configuration. This didn’t happen on play 2.4

My build.sbt:

version := "1.0-SNAPSHOT"

lazy val root = (project in file(".")).enablePlugins(PlayJava)

scalaVersion := "2.12.6"

libraryDependencies += filters
libraryDependencies += guice
libraryDependencies += ws

libraryDependencies ++= Seq(
  "org.hibernate" % "hibernate-core" % "5.4.1.Final" // replace by your jpa implementation
libraryDependencies += "mysql" % "mysql-connector-java" % "8.0.12"
libraryDependencies += "com.auth0" % "java-jwt" % "3.5.0"

PlayKeys.externalizeResources := false


<persistence xmlns=""

    <persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">
            <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>


(Patrick Li) #2

I think I have seen this before. As I recall, it is caused by the line below and how resources or classes are loaded between development and production (they are handled a bit differently). At the end, just add your entities in your persistence.xml file and it will always work.

PlayKeys.externalizeResources := false