package names (namespaces) in subproject classes in Play Framework

柔情痞子 提交于 2019-12-01 12:31:44
masterdany88

I've found solution.

It dosn't matter how I named packages. One requirement from play framework is to start name of package with:

  • controllers - in case of naming controller package (f.e: package controllers.common;)
  • models - in case of naming model package (f.e: package models.common;, or just package models; )

Runtime error:

[IllegalArgumentException: Unknown entity: models.Cart]

Is caused by Jpa/Hibernate configuration. Problem is that Jpa/Hibernate sees my entities (mark by annotation @Entity) while compilation, but in runtime dosn't. To fix that I've to manually point all my models class (entitites) in persistance.xml file as follow:

/conf/META-INF/persistence.xml

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0">

    <persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <non-jta-data-source>DefaultDS</non-jta-data-source>
            <class>models.AppMode</class>
            <class>models.Customer</class>
            <class>models.Complaint</class>
        <properties>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
            <property name="hibernate.show_sql" value="true"/>
        </properties>
    </persistence-unit>
</persistence>

See more here: How to persist models entity in playframework submodule using jpa/hibernate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!