我正在使用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上运行时所需的功能. 总结
以上是内存溢出为你收集整理的javax.persistence.EntityManager.getCriteriaBuilder()Ljavax / persistence / criteria / CriteriaBuilder 全部内容,希望文章能够帮你解决javax.persistence.EntityManager.getCriteriaBuilder()Ljavax / persistence / criteria / CriteriaBuilder 所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)