[英]Hibernate on Glassfish not an entity exception
I have the following problem: The application is deployed successfully, but whenever i try to execute a query it ends up like this: 我有以下问题:应用程序已成功部署,但是每当我尝试执行查询时,它最终都会像这样:
Caused by: java.lang.IllegalArgumentException: Not an entity: class javaeetutorial.addressbook.entity.Contact
So here are my configs: 所以这是我的配置:
Persistence.xml persistence.xml中
<persistence-unit name="address-bookPU" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>jdbc/PostgreSQLDataSource</jta-data-source>
<class>javaeetutorial.addressbook.entity.Contact</class>
<properties>
<property name="hibernate.archive.autodetection" value="class, hbm"/>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.SunOneJtaPlatform" />
<property name="show_sql" value="true"/>
</properties>
</persistence-unit>
The entity class is annotated with @Entity of course. 实体类当然用@Entity注释。
Can anyone help me solve this issue? 谁能帮我解决这个问题?
I spent two days and found the following solution. 我花了两天时间,发现以下解决方案。 1. Use at least Hibernate 4.3.10:
1.至少使用Hibernate 4.3.10:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.10.Final</version>
</dependency>
2. Change persistence.xml as follows (schema 2.1, provider <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
, two properties - a MUST): 2.如下更改persistence.xml(模式2.1,提供程序
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
,两个属性-必须):
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" 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">
<persistence-unit name="your_pu" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>jdbc/your_src</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.archive.autodetection" value="class, hbm, jar"/>
<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.SunOneJtaPlatform"/>
</properties>
</persistence-unit>
</persistence>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.