对于EntityManager类型,未定义方法createEntityGraph(Class<>)

时间:2014-10-28 01:17:36

标签: java eclipse maven jpa

以下代码行:

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

1 个答案:

答案 0 :(得分:1)

您的jee7项目未正确设置,您必须添加此依赖项:

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