我正在使用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>
最佳答案
方法EntityManager.getCriteriaBuilder是JPA 2(属于Java EE 6的一部分)的一部分,JPA 2在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从3.x开始就有标准.您可以创建一个Hibernate会话工厂,而不是EntityManager.然后,您可以执行以下操作:
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上运行时所需的功能.