NamedEntityGraph无法解析为类型 [英] NamedEntityGraph cannot be resolved to a type
问题描述
NamedEntityGraph无法解析为类型
和
NamedAttributeNode无法解析为类型
如何解决这些编译错误?
以下是显示编译错误的代码行:
@Entity(name =someclass)
pre>
@NamedEntityGraph(name =includeOther,attributeNodes = {@ NamedAttributeNode(other) $)
@Table(name =sometable)
public class SomeClass {
//很多东西
}
我认为问题是eclipse没有看到我配置了JPA 2.1。但是我试图安装和配置JPA 2.1。您可以在文件共享站点通过点击此链接阅读我的pom.xml的整个代码一>。我在eclipse项目方面设置了JPA 2.1,您可以通过点击此链接查看 。此外,我从Windows命令行在eclipse项目的根文件夹上运行
mvn依赖:tree
,并得到以下输出:[INFO]
[INFO] ------------------------ ------------------------------------------------
[INFO]构建MyApp 1.0.0-SNAPSHOT
[INFO] ------------------------------- -----------------------------------------
[警告]工件org.apache.commons:commons-io:jar:1.3.2已经被重定位到commons-io:commons-io:jar:1.3.2
[INFO]
[INFO] --- maven -dependency-plugin:2.8:tree(default-cli)@ MyApp ---
[WARNING]工件org.apache.commons:commons-io:jar:1.3.2已被重定位到commons-io: commons-io:jar:1.3.2
[INFO] org.springframework.samples:MyApp:war:1.0.0-SNAPSHOT
[INFO] + - org.jvnet.hyperjaxb3:hyperjaxb3-ejb- runtime:jar:0.6.0:compile
[INFO] | + - org.apache.commons:commons-lang3:jar:3.2.1:compile
[INFO] | \- org.jvnet.jaxb2_commons:jaxb2-basics-runtime:jar:0.8.2:compile
[INFO] + - org.jvnet.hyperjaxb3:hyperjaxb3-ejb-roundtrip:jar:0.6.0:compile
[INFO] | + - org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.0.Final:compile
[INFO] | + - org.jvnet.jaxb2_commons:jaxb2-basics-testing:jar:0.8.2:compile
[INFO] | | + - xmlunit:xmlunit:jar:1.0:compile
[INFO] | | \- org.jvnet.jaxb2_commons:jaxb2-basics-tools:jar:0.8.2:compile
[INFO] | | \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] | \- org.slf4j:slf4j-log4j12:jar:1.6.1:compile
[INFO] | \- log4j:log4j:jar:1.2.16:compile
[INFO] + - org.jadira.usertype:usertype.core:jar:3.1.0.CR8:compile
[INFO] | \- org.jadira.usertype:usertype.spi:jar:3.1.0.CR8:compile
[INFO] + - javax.servlet:jstl:jar:1.2:compile
[INFO] + - javax.servlet:servlet-api:jar:2.5:提供
[INFO] + - javax.servlet.jsp:jsp-api:jar:2.2:提供
[INFO] + - org.springframework .data:spring-data-jpa:jar:1.6.4.RELEASE:compile
[INFO] | + - org.springframework.data:spring-data-commons:jar:1.8.4.RELEASE:compile
[INFO] | + - org.springframework:spring-context:jar:4.0.6.RELEASE:compile
[INFO] | + - org.springframework:spring-beans:jar:4.0.6.RELEASE:compile
[INFO] | + - org.springframework:spring-core:jar:4.0.6.RELEASE:compile
[INFO] | \- org.slf4j:jcl-over-slf4j:jar:1.7.7:runtime
[INFO] + - org.springframework:spring-jdbc:jar:4.0.6.RELEASE:compile
[INFO] + - org.springframework:spring-aop:jar:4.0.6.RELEASE:compile
[INFO] | \- aopalliance:aopalliance:jar:1.0:compile
[INFO] + - org.springframework:spring-webmvc:jar:4.0.6.RELEASE:compile
[INFO] | + - org.springframework:spring-expression:jar:4.0.6.RELEASE:compile
[INFO] | \- org.springframework:spring-web:jar:4.0.6.RELEASE:compile
[INFO] + - org.springframework:spring-tx:jar:4.0.6.RELEASE:compile
[INFO] + - org.springframework:spring-context-support:jar:4.0.6.RELEASE:compile
[INFO] + - org.springframework:spring-orm:jar:4.0.6.RELEASE:compile
[INFO] + - org.springframework:spring-oxm:jar:4.0.6.RELEASE:compile
[INFO] + - org.springframework:spring-jms:jar:4.0.6.RELEASE :编译
[INFO] + - org.apache.tomcat:tomcat-jdbc:jar:7.0.42:runtime
[INFO] | \- org.apache.tomcat:tomcat-juli:jar:7.0.42:runtime
[INFO] + - org.slf4j:slf4j-api:jar:1.7.5:compile
[INFO ] + - ch.qos.logback:logback-classic:jar:1.0.13:runtime
[INFO] | \- ch.qos.logback:logback-core:jar:1.0.13:runtime
[INFO] + - joda-time:joda-time:jar:2.3:compile
[INFO] + - joda-time:joda-time-hibernate:jar:1.3:compile
[INFO] + - joda-time:joda-time-jsptags:jar:1.1.1:compile
[INFO] - org.jadira.usertype:usertype.jodatime:jar:2.0.1:compile
[INFO] + - mysql:mysql-connector-java:jar:5.1.27:compile
[INFO] + - org.hibernate:hibernate-entitymanager:jar:4.2.1.Final:compile
[INFO] | + - org.jboss.logging:jboss-logging:jar:3.1.0.GA:compile
[INFO] | + - org.hibernate:hibernate-core:jar:4.2.1.Final:compile
[INFO] | | \- antlr:antlr:jar:2.7.7:compile
[INFO] | + - dom4j:dom4j:jar:1.6.1:compile
[INFO] | + - org.jboss.spec.javax.transaction:jboss-transaction api_1.1_spec:jar:1.0.1.Final:compile
[INFO] | + - org.javassist:javassist:jar:3.15.0-GA:compile
[INFO] | \- org.hibernate.common:hibernate-commons-annotations:jar:4.0.1.Final:compile
[INFO] + - org.hibernate:hibernate-validator:jar:5.1.1.Final:compile
[INFO] | + - javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] | \- com.fasterxml:classmate:jar:1.0.0:compile
[INFO] + - org.hibernate:hibernate-ehcache:jar:4.2.1.Final:compile
[INFO] + - net.sf.ehcache:ehcache-core:jar:2.6.6:编译
[INFO] + - org.webjars:bootstrap:jar:2.3.0:compile
[INFO] + - org .webjars:jquery-ui:jar:1.10.3:compile
[INFO] + - org.webjars:jquery:jar:2.0.3-1:compile
[INFO] + - org.springframework :spring-test:jar:4.0.6.RELEASE:test
[INFO] + - junit:junit:jar:4.11:test
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] + - org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] + - org.aspectj :aspectjrt:jar:1.7.4:compile
[INFO] + - org.aspectj:aspectjweaver:jar:1.7.4:runtime
[INFO] + - com.github.dandelion:datatables-jsp :jar:0.9.2:compile
[INFO] | \- com.github.dandelion:datatables-core:jar:0.9.2:compile
[INFO] | + - com.googlecode.json-simple:json-simple:jar:1.1.1:compile
[INFO] | \- commons-beanutils:commons-beanutils:jar:1.8.3:compile
[INFO] + - com.github.dandelion:datatables-export-itext:jar:0.9.2:compile
[INFO] | \- com.itextpdf:itextpdf:jar:5.3.4:编译
[INFO] + - com.github.dandelion:datatables-servlet2:jar:0.9.2:compile
[INFO] + - commons-fileupload:commons-fileupload:jar:1.2:compile
[INFO] + - commons-io:commons-io:jar:1.3.2:compile
[INFO] + - commons-lang :commons-lang:jar:2.6:compile
[INFO] + - org.apache.tiles:tiles-jsp:jar:2.1.3:compile
[INFO] | \- org.apache.tiles:tiles-servlet:jar:2.1.3:compile
[INFO] | \- org.apache.tiles:tiles-core:jar:2.1.3:compile
[INFO] | + - org.apache.tiles:tiles-api:jar:2.1.3:compile
[INFO] | \- commons-digester:commons-digester:jar:1.8.1:compile
[INFO] + - org.springframework.security:spring-security-core:jar:3.2.2.RELEASE:compile
[INFO] + - org.springframework.security:spring-security-web:jar:3.2.2.RELEASE:compile
[INFO] + - org.springframework.security:spring-security-config:jar :3.2.2.RELEASE:compile
[INFO] + - org.springframework.security:spring-security-taglibs:jar:3.2.2.RELEASE:compile
[INFO] | \- org.springframework.security:spring-security-acl:jar:3.2.2.RELEASE:compile
[INFO] + - org.eclipse.emf:ecore:jar:2.2.3:compile
[INFO] \- org.eclipse.emf:common:jar:2.2.3:compile
[INFO] -------------------- -------------------------------------------------- -
[INFO] BUILD SUCCESS
[INFO] -------------------------------- ----------------------------------------
[INFO]总时间: 9.805s
[INFO]完成时间:星期四06 06:32:32 PST 2014
[INFO] Final Memory:14M / 124M
[INFO] -------- -------------------------------------------------- --------------
解决方案
org.hibernate:hibernate-entitymanager:jar:4.2.1.Final:compile
我不认为Hibernate 4.2.1支持JPA 2.1。您可能需要升级到Hibernate 4.3。
如果应用程序容器不提供,您可能还需要添加此依赖项:
<依赖关系>
< groupId> org.hibernate.javax.persistence< / groupId>
< artifactId> hibernate-jpa-2.1-api< / artifactId>
< version> 1.0.0.Final< / version>
< / dependency>
In an eclipse project that uses maven, jpa, and hibernate, I am getting the following two compilation errors:
NamedEntityGraph cannot be resolved to a type and NamedAttributeNode cannot be resolved to a type
How can I resolve these compilation errors?
Here is the line of code that is showing the compilation errors:
@Entity(name="someclass") @NamedEntityGraph(name="includeOther", attributeNodes={@NamedAttributeNode("other")}) @Table(name="sometable") public class SomeClass { //lots of stuff }
I think the problem is that eclipse is not seeing that I have JPA 2.1 configured. But I have tried to install and configure JPA 2.1. You can read the entire code of my pom.xml at a file sharing site by clicking on this link. I set up JPA 2.1 in the eclipse project facets, which you can see by clicking on this link. Also, I ran
mvn dependency:tree
on the root folder of the eclipse project from the windows command line, and I got the following output:[INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building MyApp 1.0.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [WARNING] The artifact org.apache.commons:commons-io:jar:1.3.2 has been relocated to commons-io:commons-io:jar:1.3.2 [INFO] [INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ MyApp --- [WARNING] The artifact org.apache.commons:commons-io:jar:1.3.2 has been relocated to commons-io:commons-io:jar:1.3.2 [INFO] org.springframework.samples:MyApp:war:1.0.0-SNAPSHOT [INFO] +- org.jvnet.hyperjaxb3:hyperjaxb3-ejb-runtime:jar:0.6.0:compile [INFO] | +- org.apache.commons:commons-lang3:jar:3.2.1:compile [INFO] | \- org.jvnet.jaxb2_commons:jaxb2-basics-runtime:jar:0.8.2:compile [INFO] +- org.jvnet.hyperjaxb3:hyperjaxb3-ejb-roundtrip:jar:0.6.0:compile [INFO] | +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.0.Final:compile [INFO] | +- org.jvnet.jaxb2_commons:jaxb2-basics-testing:jar:0.8.2:compile [INFO] | | +- xmlunit:xmlunit:jar:1.0:compile [INFO] | | \- org.jvnet.jaxb2_commons:jaxb2-basics-tools:jar:0.8.2:compile [INFO] | | \- commons-logging:commons-logging:jar:1.1.1:compile [INFO] | \- org.slf4j:slf4j-log4j12:jar:1.6.1:compile [INFO] | \- log4j:log4j:jar:1.2.16:compile [INFO] +- org.jadira.usertype:usertype.core:jar:3.1.0.CR8:compile [INFO] | \- org.jadira.usertype:usertype.spi:jar:3.1.0.CR8:compile [INFO] +- javax.servlet:jstl:jar:1.2:compile [INFO] +- javax.servlet:servlet-api:jar:2.5:provided [INFO] +- javax.servlet.jsp:jsp-api:jar:2.2:provided [INFO] +- org.springframework.data:spring-data-jpa:jar:1.6.4.RELEASE:compile [INFO] | +- org.springframework.data:spring-data-commons:jar:1.8.4.RELEASE:compile [INFO] | +- org.springframework:spring-context:jar:4.0.6.RELEASE:compile [INFO] | +- org.springframework:spring-beans:jar:4.0.6.RELEASE:compile [INFO] | +- org.springframework:spring-core:jar:4.0.6.RELEASE:compile [INFO] | \- org.slf4j:jcl-over-slf4j:jar:1.7.7:runtime [INFO] +- org.springframework:spring-jdbc:jar:4.0.6.RELEASE:compile [INFO] +- org.springframework:spring-aop:jar:4.0.6.RELEASE:compile [INFO] | \- aopalliance:aopalliance:jar:1.0:compile [INFO] +- org.springframework:spring-webmvc:jar:4.0.6.RELEASE:compile [INFO] | +- org.springframework:spring-expression:jar:4.0.6.RELEASE:compile [INFO] | \- org.springframework:spring-web:jar:4.0.6.RELEASE:compile [INFO] +- org.springframework:spring-tx:jar:4.0.6.RELEASE:compile [INFO] +- org.springframework:spring-context-support:jar:4.0.6.RELEASE:compile [INFO] +- org.springframework:spring-orm:jar:4.0.6.RELEASE:compile [INFO] +- org.springframework:spring-oxm:jar:4.0.6.RELEASE:compile [INFO] +- org.springframework:spring-jms:jar:4.0.6.RELEASE:compile [INFO] +- org.apache.tomcat:tomcat-jdbc:jar:7.0.42:runtime [INFO] | \- org.apache.tomcat:tomcat-juli:jar:7.0.42:runtime [INFO] +- org.slf4j:slf4j-api:jar:1.7.5:compile [INFO] +- ch.qos.logback:logback-classic:jar:1.0.13:runtime [INFO] | \- ch.qos.logback:logback-core:jar:1.0.13:runtime [INFO] +- joda-time:joda-time:jar:2.3:compile [INFO] +- joda-time:joda-time-hibernate:jar:1.3:compile [INFO] +- joda-time:joda-time-jsptags:jar:1.1.1:compile [INFO] +- org.jadira.usertype:usertype.jodatime:jar:2.0.1:compile [INFO] +- mysql:mysql-connector-java:jar:5.1.27:compile [INFO] +- org.hibernate:hibernate-entitymanager:jar:4.2.1.Final:compile [INFO] | +- org.jboss.logging:jboss-logging:jar:3.1.0.GA:compile [INFO] | +- org.hibernate:hibernate-core:jar:4.2.1.Final:compile [INFO] | | \- antlr:antlr:jar:2.7.7:compile [INFO] | +- dom4j:dom4j:jar:1.6.1:compile [INFO] | +- org.jboss.spec.javax.transaction:jboss-transaction api_1.1_spec:jar:1.0.1.Final:compile [INFO] | +- org.javassist:javassist:jar:3.15.0-GA:compile [INFO] | \- org.hibernate.common:hibernate-commons-annotations:jar:4.0.1.Final:compile [INFO] +- org.hibernate:hibernate-validator:jar:5.1.1.Final:compile [INFO] | +- javax.validation:validation-api:jar:1.1.0.Final:compile [INFO] | \- com.fasterxml:classmate:jar:1.0.0:compile [INFO] +- org.hibernate:hibernate-ehcache:jar:4.2.1.Final:compile [INFO] +- net.sf.ehcache:ehcache-core:jar:2.6.6:compile [INFO] +- org.webjars:bootstrap:jar:2.3.0:compile [INFO] +- org.webjars:jquery-ui:jar:1.10.3:compile [INFO] +- org.webjars:jquery:jar:2.0.3-1:compile [INFO] +- org.springframework:spring-test:jar:4.0.6.RELEASE:test [INFO] +- junit:junit:jar:4.11:test [INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test [INFO] +- org.hamcrest:hamcrest-library:jar:1.3:test [INFO] +- org.aspectj:aspectjrt:jar:1.7.4:compile [INFO] +- org.aspectj:aspectjweaver:jar:1.7.4:runtime [INFO] +- com.github.dandelion:datatables-jsp:jar:0.9.2:compile [INFO] | \- com.github.dandelion:datatables-core:jar:0.9.2:compile [INFO] | +- com.googlecode.json-simple:json-simple:jar:1.1.1:compile [INFO] | \- commons-beanutils:commons-beanutils:jar:1.8.3:compile [INFO] +- com.github.dandelion:datatables-export-itext:jar:0.9.2:compile [INFO] | \- com.itextpdf:itextpdf:jar:5.3.4:compile [INFO] +- com.github.dandelion:datatables-servlet2:jar:0.9.2:compile [INFO] +- commons-fileupload:commons-fileupload:jar:1.2:compile [INFO] +- commons-io:commons-io:jar:1.3.2:compile [INFO] +- commons-lang:commons-lang:jar:2.6:compile [INFO] +- org.apache.tiles:tiles-jsp:jar:2.1.3:compile [INFO] | \- org.apache.tiles:tiles-servlet:jar:2.1.3:compile [INFO] | \- org.apache.tiles:tiles-core:jar:2.1.3:compile [INFO] | +- org.apache.tiles:tiles-api:jar:2.1.3:compile [INFO] | \- commons-digester:commons-digester:jar:1.8.1:compile [INFO] +- org.springframework.security:spring-security-core:jar:3.2.2.RELEASE:compile [INFO] +- org.springframework.security:spring-security-web:jar:3.2.2.RELEASE:compile [INFO] +- org.springframework.security:spring-security-config:jar:3.2.2.RELEASE:compile [INFO] +- org.springframework.security:spring-security-taglibs:jar:3.2.2.RELEASE:compile [INFO] | \- org.springframework.security:spring-security-acl:jar:3.2.2.RELEASE:compile [INFO] +- org.eclipse.emf:ecore:jar:2.2.3:compile [INFO] \- org.eclipse.emf:common:jar:2.2.3:compile [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 9.805s [INFO] Finished at: Thu Nov 06 12:32:32 PST 2014 [INFO] Final Memory: 14M/124M [INFO] ------------------------------------------------------------------------
解决方案From your dependency tree:
org.hibernate:hibernate-entitymanager:jar:4.2.1.Final:compile
I don't think Hibernate 4.2.1 supports JPA 2.1. You may need to upgrade to Hibernate 4.3.
You may also want to add this dependency if your application container doesn't provide it:
<dependency> <groupId>org.hibernate.javax.persistence</groupId> <artifactId>hibernate-jpa-2.1-api</artifactId> <version>1.0.0.Final</version> </dependency>
这篇关于NamedEntityGraph无法解析为类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!