我正在使用Hibernate 4,Spring 3和JSF 2.0以及Weblogic 10.3.6 我在DAO课程中有以下内容
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<Request> c = cb.createQuery(Request.class);
当我运行我的应用程序时,我收到以下异常。
javax.persistence.EntityManager.getCriteriaBuilder()Ljavax/persistence/criteria
/CriteriaBuilder;
java.lang.NoSuchMethodError:
javax.persistence.EntityManager.getCriteriaBuilder()Ljavax/persistence/criteria
/CriteriaBuilder;
at net.test.request.dao.RequestDAOImpl.getRequest(RequestDAOImpl.java:51)
我没有使用JPA1罐子,但是我仍然得到这个例外。无法弄清楚如何摆脱这种异常。任何帮助都非常值得赞赏。
由于
的pom.xml
<repositories>
<repository>
<id>prime-repo</id>
<name>PrimeFaces Maven Repository</name>
<url>http://repository.primefaces.org</url>
<layout>default</layout>
</repository>
</repositories>
<properties>
<spring.version>3.1.1.RELEASE</spring.version>
</properties>
<dependencies>
<!-- Spring 3 dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- JSF library -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1.6</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.6</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- Primefaces library -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>3.4.2</version>
</dependency>
<dependency>
<groupId>org.primefaces.themes</groupId>
<artifactId>flick</artifactId>
<version>1.0.8</version>
</dependency>
<!-- Hibernate library -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.0.Final</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<!-- Oracle Java Connector library -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
</dependency>
<!-- Log4j library -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.4</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>1.2.0.Final</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgument>-proc:none</compilerArgument>
</configuration>
</plugin>
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<!-- source output directory -->
<outputDirectory>target/metamodel</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
答案 0 :(得分:3)
方法EntityManager.getCriteriaBuilder
是JPA 2(Java EE 6的一部分)的一部分,默认情况下,WebLogic 10中未提供和/或打开该方法。
这是一个链接http://docs.oracle.com/cd/E17904_01/web.1111/e13720/using_toplink.htm,提供可以解决您问题的说明。如果没有,你需要开始谷歌搜索“weblogic 10 jpa 2”,看看你是否能找到适合你的解决方案。
如果这些解决方案都不起作用,您的最后一招将是重新设计您的应用程序以仅使用JPA 1方法。要使用JPA 1,您必须将自己限制在此处定义的类和接口:http://docs.oracle.com/javaee/5/api/javax/persistence/package-summary.html
[更新]
或者 - 因为你正在使用Hibernate,所以不要太依赖JPA类。请改用特定于hibernate的类。 Hibernate自3.x起就有了标准。而不是EntityManager,您创建一个Hibernate会话工厂。然后你可以这样做:
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
...
Session session = sessionFactory.openSession();
Criteria crit = session.createCriteria(Person.class);
现在您的代码已被锁定为使用Hibernate作为持久性提供程序。在我的情况下,我们总是使用Hibernate,所以这不是一个真正的问题。这是一个你必须自己决定的问题。如果您的应用程序可以容忍被锁定到Hibernate,那么这应该为您提供在WebLogic上运行时所需的功能。