Not an entity - Hibernate

java

#1

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(
  javaJpa,
  "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.xml

<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
             version="2.1">

    <persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <non-jta-data-source>DefaultDS</non-jta-data-source>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
        </properties>
    </persistence-unit>

</persistence>

(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