[英]Strange JPA compilation errors
I get the following compile errors when trying to use JPA 2.1 and EclipseLink 2.6 尝试使用JPA 2.1和EclipseLink 2.6时出现以下编译错误
em.getCriteriaBuilder()
java: cannot find symbol symbol: method getCriteriaBuilder() location: variable em of type javax.persistence.EntityManager
java:找不到符号symbol:方法getCriteriaBuilder()位置:类型为javax.persistence.EntityManager的变量em
Expression<Boolean>
java: type javax.persistence.criteria.Expression does not take parameters
java:类型javax.persistence.criteria.Expression不带参数
TypedQuery<Foo> query = em.createQuery(queryString, Foo.class);
java: method createQuery in interface javax.persistence.EntityManager cannot be applied to given types;
java:接口javax.persistence.EntityManager中的createQuery方法不能应用于给定类型; required: java.lang.String found: java.lang.String,java.lang.Class reason: actual and formal argument lists differ in length
必需:找到的java.lang.String:java.lang.String,java.lang.Class原因:实际参数和形式参数列表的长度不同
My pom.xml contains the following dependencies for JPA 我的pom.xml包含以下JPA依赖项
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.6.0</version>
</dependency>
I can only think that the compiler is using a different JPA version where such methods I am trying to use above did not exist. 我只能认为编译器使用的是其他JPA版本,而我尝试使用的上述方法不存在。 However the pom clearly contains the 2.1 implementation.
但是pom显然包含2.1的实现。
These compilation errors are happening while I am attempting to convert a non maven project to an Intellij IDEA maven project (so everything worked before). 当我尝试将非maven项目转换为Intellij IDEA maven项目时,发生了这些编译错误(因此之前所有工作都可以进行)。
Full pom.xml 完整的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<groupId>REDACTED</groupId>
<artifactId>REDACTED</artifactId>
<properties>
<appengine.app.version>1</appengine.app.version>
<appengine.target.version>1.7.5</appengine.target.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- Compile/runtime dependencies -->
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>${appengine.target.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<!-- if your container implements Servlet API older than 3.0, use "jersey-container-servlet-core" -->
<artifactId>jersey-container-servlet</artifactId>
<version>2.17</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-mvc</artifactId>
<version>2.17</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>3.2.6.RELEASE</version>
</dependency>
<!-- Test Dependencies -->
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-testing</artifactId>
<version>${appengine.target.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-stubs</artifactId>
<version>${appengine.target.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<version>2.5.1</version>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<archiveClasses>true</archiveClasses>
<webResources>
<!-- in order to interpolate version from pom into appengine-web.xml -->
<resource>
<directory>${basedir}/src/main/webapp/WEB-INF</directory>
<filtering>true</filtering>
<targetPath>WEB-INF</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>${appengine.target.version}</version>
</plugin>
</plugins>
</build>
Edit: result of running mvn dependency:tree 编辑:运行MVN依赖项的结果:树
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ REDACTED ---
[INFO] REDACTED:war:0.0.1-SNAPSHOT
[INFO] +- com.google.appengine:appengine-api-1.0-sdk:jar:1.7.5:compile
[INFO] +- javax.servlet:servlet-api:jar:2.5:provided (scope not updated to
compile)
[INFO] +- jstl:jstl:jar:1.2:compile
[INFO] +- org.eclipse.persistence:javax.persistence:jar:2.1.0:compile
[INFO] +- org.eclipse.persistence:eclipselink:jar:2.6.0:compile
[INFO] | +- org.eclipse.persistence:commonj.sdo:jar:2.1.1:compile
[INFO] | +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] | \- org.glassfish:javax.json:jar:1.0.4:compile
[INFO] +- mysql:mysql-connector-java:jar:5.1.6:compile
[INFO] +- javax.ws.rs:javax.ws.rs-api:jar:2.0.1:provided (scope not updated to compile)
[INFO] +- org.glassfish.jersey.containers:jersey-container-servlet:jar:2.17:compile
[INFO] | +- org.glassfish.jersey.containers:jersey-container-servlet-core:jar:2.17:compile
[INFO] | | \- org.glassfish.hk2.external:javax.inject:jar:2.4.0-b10:compile
[INFO] | +- org.glassfish.jersey.core:jersey-common:jar:2.17:compile
[INFO] | | +- javax.annotation:javax.annotation-api:jar:1.2:compile
[INFO] | | +- org.glassfish.jersey.bundles.repackaged:jersey-guava:jar:2.17:compile
[INFO] | | +- org.glassfish.hk2:hk2-api:jar:2.4.0-b10:compile
[INFO] | | | +- org.glassfish.hk2:hk2-utils:jar:2.4.0-b10:compile
[INFO] | | | \- org.glassfish.hk2.external:aopalliance-repackaged:jar:2.4.0-b10:compile
[INFO] | | +- org.glassfish.hk2:hk2-locator:jar:2.4.0-b10:compile
[INFO] | | | \- org.javassist:javassist:jar:3.18.1-GA:compile
[INFO] | | \- org.glassfish.hk2:osgi-resource-locator:jar:1.0.1:compile
[INFO] | \- org.glassfish.jersey.core:jersey-server:jar:2.17:compile
[INFO] | +- org.glassfish.jersey.core:jersey-client:jar:2.17:compile
[INFO] | \- org.glassfish.jersey.media:jersey-media-jaxb:jar:2.17:compile
[INFO] +- org.glassfish.jersey.ext:jersey-mvc:jar:2.17:compile
[INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.5.1:compile
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.5.1:compile
[INFO] +- com.fasterxml.jackson.core:jackson-annotations:jar:2.5.1:compile
[INFO] +- org.springframework.security:spring-security-web:jar:3.2.6.RELEASE:compile
[INFO] | +- aopalliance:aopalliance:jar:1.0:compile
[INFO] | +- org.springframework.security:spring-security-core:jar:3.2.6.RELEASE:compile
[INFO] | | \- org.springframework:spring-aop:jar:3.2.8.RELEASE:compile
[INFO] | +- org.springframework:spring-beans:jar:3.2.8.RELEASE:compile
[INFO] | +- org.springframework:spring-context:jar:3.2.8.RELEASE:compile
[INFO] | +- org.springframework:spring-core:jar:3.2.8.RELEASE:compile
[INFO] | +- org.springframework:spring-expression:jar:3.2.8.RELEASE:compile
[INFO] | \- org.springframework:spring-web:jar:3.2.8.RELEASE:compile
[INFO] +- com.google.appengine:appengine-testing:jar:1.7.5:test
[INFO] \- com.google.appengine:appengine-api-stubs:jar:1.7.5:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
I believe the Google App Engine and Maven Facets of Intellij IDEA are incompatible. 我相信Intellij IDEA的Google App Engine和Maven Facets不兼容。 I chose to create the project from the skeleton-archetype of com.google.appengine.archetypes and ignored the GAE IDE integration feature.
我选择从com.google.appengine.archetypes的框架原型创建项目,而忽略了GAE IDE集成功能。 This solved the compliation errors.
这样解决了编译错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.