[我将在工作于Oracle9i数据库的应用程序中引入JPA2.0,并添加了EclipseLink(JPA2.0)库并创建了实体类,但是当我使用时,
javax.persistence.criteria.CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
我收到以下错误
找不到符号符号:方法getCriteriaBuilder()位置:接口javax.persistence.EntityManager
我的web.xml是2.4版,这是我的persistence.xml
<persistence version="2.0" 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">
<persistence-unit name="MiraclinPU" transaction-type="JTA">
<jta-data-source>jdbc/Miraclin</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties/>
</persistence-unit>
</persistence>
好像我在论坛上阅读的一样,该应用正在使用JPA1.0。有人可以帮忙吗?
用途:
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
而不是:
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>
搜索项目中包含的所有库,并除去包含persistence.xml的库(所需库除外)。然后再次包含它们。
日食:
如何验证:
在您的sourceDAO.java中,在EntityManagerFactory中按F3并查看打开了什么.jar eclipse。
您的类路径中有ejb3-persistence.jar。
其实体管理器没有此方法。
缺少
import javax.persistence.criteria.*;
可能吗?
[Due to org.hibernate.orm
工件已移至hibernate-core
;我从pom.xml
中删除了它:
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.9.Final</version>
</dependency>
并添加此:
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.9.Final</version>
</dependency>
解决了cannot find symbol getCriteriaBuilder()
问题。