我在我的Oracle9i数据库应用程序中引入了JPA2.0,并添加了EclipseLink(JPA2.0)库并创建了实体类,但是当我使用
时javax.persistence.criteria.CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
我收到以下错误
无法找到符号 符号:方法getCriteriaBuilder() location:接口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,因为我在论坛上阅读...有人可以帮忙吗?
答案 0 :(得分:4)
搜索项目中包含的所有库,并删除包含persistence.xml的库,除了您需要的库。然后再次重新加入它们。
答案 1 :(得分:4)
使用:
<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>
答案 2 :(得分:2)
在日食中:
如何验证:
在sourceDAO.java中的按下EntityManagerFactory中的 F3 ,看看.jar eclipse打开了什么。
答案 3 :(得分:0)
你的类路径中有ejb3-persistence.jar。
其实体经理没有这种方法。
答案 4 :(得分:0)
缺少
import javax.persistence.criteria.*;
可能?
答案 5 :(得分:0)
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()
问题。