我找到了解决方案。
我如何命名软件包都没关系。播放框架的一项要求是,以以下名称开头包的名称:
运行时错误:
[IllegalArgumentException: UnkNown entity: models.Cart]
是由Jpa /休眠配置引起的。问题在于,Jpa / Hibernate在编译时会看到我的实体(通过@Entity标记),但在运行时却看不到。要解决此问题,我必须手动将所有模型类(实体)指向persistance.xml文件,如下所示:
/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>