gpt4 book ai didi

java - Glassfish 上的 Hibernate 不是实体异常

转载 作者:太空宇宙 更新时间:2023-11-04 14:27:45 26 4
gpt4 key购买 nike

我有以下问题:应用程序已成功部署,但每当我尝试执行查询时,结果都会像这样:

Caused by: java.lang.IllegalArgumentException: Not an entity: class javaeetutorial.addressbook.entity.Contact

这是我的配置:

持久性.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>

实体类当然是用@Entity注释的。

谁能帮我解决这个问题吗?

最佳答案

我花了两天时间找到了以下解决方案。1. 至少使用Hibernate 4.3.10:

    <dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.10.Final</version>
</dependency>

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>

关于java - Glassfish 上的 Hibernate 不是实体异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26492183/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com