java javax.persistence.EntityManager.getCriteriaBuilder()Ljavax/persistence/criteria/CriteriaBuilder

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13980546/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 14:38:08  来源:igfitidea点击:

javax.persistence.EntityManager.getCriteriaBuilder()Ljavax/persistence/criteria/CriteriaBuilder

javaspringhibernate

提问by J?cob

I am using Hibernate 4, Spring 3 and JSF 2.0 and Weblogic 10.3.6 I have the following in DAO class

我正在使用 Hibernate 4、Spring 3 和 JSF 2.0 和 Weblogic 10.3.6 我在 DAO 类中有以下内容

        CriteriaBuilder cb = entityManager.getCriteriaBuilder();
        CriteriaQuery<Request> c = cb.createQuery(Request.class);

When I run my application I am getting the following exception.

当我运行我的应用程序时,我收到以下异常。

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)

I did not use JPA1 jars, however I am still getting this exception. Not able to figure how to get rid of this exception. Any help is highly appreciable.

我没有使用 JPA1 罐子,但是我仍然遇到这个异常。无法弄清楚如何摆脱这个异常。任何帮助都是非常可观的。

Thanks

谢谢

pom.xml

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>

采纳答案by Guido Simone

The method EntityManager.getCriteriaBuilderis a part of JPA 2 (which is part of Java EE 6), which is not provided and/or turned on by default in WebLogic 10.

该方法EntityManager.getCriteriaBuilder是 JPA 2(它是 Java EE 6 的一部分)的一部分,在 WebLogic 10 中默认不提供和/或打开。

Here is a link http://docs.oracle.com/cd/E17904_01/web.1111/e13720/using_toplink.htmwhich provides instructions that may fix your problem. If not, you'll need to start googling "weblogic 10 jpa 2" and see if you can find a solution that works for you.

这是一个链接http://docs.oracle.com/cd/E17904_01/web.1111/e13720/using_toplink.htm,它提供了可以解决您的问题的说明。如果没有,您需要开始使用谷歌搜索“weblogic 10 jpa 2”,看看是否能找到适合您的解决方案。

If none of these solutions work, your last resort will be to redesign your application to only use JPA 1 methods. To use JPA 1 you must limit yourself to the classes and interfaces defined here: http://docs.oracle.com/javaee/5/api/javax/persistence/package-summary.html

如果这些解决方案都不起作用,您最后的手段就是重新设计您的应用程序,使其仅使用 JPA 1 方法。要使用 JPA 1,您必须将自己限制在此处定义的类和接口:http: //docs.oracle.com/javaee/5/api/javax/persistence/package-summary.html

[update]

[更新]

Or - since you are using Hibernate anyways, don't rely so much on JPA classes. Use hibernate specific classes instead. Hibernate has had criteria since 3.x. Instead of an EntityManager you create a Hibernate session factory. Then you can do:

或者 - 由于您无论如何都在使用 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);

Your code is now locked into using Hibernate as your persistence provider. In my case we always use Hibernate so it's not a real problem. This is a question you have to decide for yourself. If your application can tolerate being locked into Hibernate, this should give you the functionality you need while still running on WebLogic.

您的代码现在被锁定为使用 Hibernate 作为您的持久性提供者。就我而言,我们总是使用 Hibernate,所以这不是一个真正的问题。这是一个你必须自己决定的问题。如果您的应用程序可以容忍被锁定在 Hibernate 中,那么这应该会为您提供所需的功能,同时仍在 WebLogic 上运行。