【问题标题】:The method createEntityGraph(Class<>) is undefined for the type EntityManagerEntityManager 类型的 createEntityGraph(Class<>) 方法未定义
【发布时间】:2014-12-23 07:58:51
【问题描述】:

以下代码行:

EntityGraph<Patient> graph = this.em.createEntityGraph(Patient.class);

在eclipse中导致以下编译错误:

The method createEntityGraph(Class<SomeClass>) is undefined for the type EntityManager  

如何解决此错误?

以下是我的 pom.xml 的相关部分:

<properties>
    <!-- Generic properties -->
    <java.version>1.7</java.version>
    <!-- Spring -->
    <spring-framework.version>4.0.6.RELEASE</spring-framework.version>
    <spring-data-jpa.version>1.6.4.RELEASE</spring-data-jpa.version>
    <!-- Hibernate / JPA -->
    <hibernate.version>4.3.5.Final</hibernate.version>
    <!-- Bean validation -->
    <hibernate-validator.version>5.1.1.Final</hibernate-validator.version>
    <!-- Database access -->
    <tomcat-jdbc.version>7.0.42</tomcat-jdbc.version>
    <mysql.version>5.1.27</mysql.version>
    <!-- AOP -->
    <aspectj.version>1.7.4</aspectj.version>
</properties>

<dependencies>
    <!-- hyperjaxb dependencies -->
    <dependency>
        <groupId>org.jvnet.hyperjaxb3</groupId>
        <artifactId>hyperjaxb3-ejb-runtime</artifactId>
        <version>0.6.0</version>
    </dependency>
    <!-- Roundtrip -->
    <dependency>
        <groupId>org.jvnet.hyperjaxb3</groupId>
        <artifactId>hyperjaxb3-ejb-roundtrip</artifactId>
        <version>0.6.0</version>
    </dependency>
    <!-- SPRING, SPRING, SPRINGITY SPRING -->
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>${spring-data-jpa.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>${spring-framework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>${spring-framework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring-framework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>${spring-framework.version}</version>
    </dependency>
    <!-- used for EhCcheCcheManager -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>${spring-framework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${spring-framework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-oxm</artifactId>
        <version>${spring-framework.version}</version>
        <exclusions>
            <exclusion>
                <groupId>commons-lang</groupId>
                <artifactId>commons-lang</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jms</artifactId>
        <version>${spring-framework.version}</version>
    </dependency>
    <!-- Database connection pool -->
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-jdbc</artifactId>
        <version>${tomcat-jdbc.version}</version>
        <scope>runtime</scope>
    </dependency>
    <!-- For MySql only -->
    <dependency> 
        <groupId>mysql</groupId> 
        <artifactId>mysql-connector-java</artifactId> 
        <version>${mysql.version}</version> 
    </dependency>
    <!-- HIBERNATE -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>${hibernate.version}</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>${hibernate-validator.version}</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-ehcache</artifactId>
        <version>${hibernate.version}</version>
    </dependency>
</dependencies>

另外,在eclipse项目方面,JPA version设置为2.1

【问题讨论】:

    标签: java eclipse maven jpa


    【解决方案1】:

    你的jee7项目没有正确设置你必须添加这个依赖:

        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
    

    【讨论】:

    • 这并没有解决问题。我将依赖添加到pom.xml,然后在eclipse中做了maven download sourcesmaven update project,但是编译错误并没有消失。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-12
    • 1970-01-01
    相关资源
    最近更新 更多