Jpa 无法将eclipselink与spring boot一起使用
我有一个Spring Boot 1.4应用程序,我正在尝试使用Eclipselink代替Hibernate。Jpa 无法将eclipselink与spring boot一起使用,jpa,spring-boot,spring-data,eclipselink,spring-data-jpa,Jpa,Spring Boot,Spring Data,Eclipselink,Spring Data Jpa,我有一个Spring Boot 1.4应用程序,我正在尝试使用Eclipselink代替Hibernate。 现在,我就是这么做的: 已从deps中删除休眠 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> <exclusions> &
现在,我就是这么做的:
已从deps中删除休眠
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</exclusion>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</exclusion>
</exclusions>
</dependency>
当我运行应用程序时,它会在数据库中创建表(表示我的模型),然后抛出以下错误:
Caused by: java.lang.ClassCastException: org.eclipse.persistence.internal.jpa.metamodel.SingularAttributeImpl cannot be cast to javax.persistence.metamodel.PluralAttribute
at org.eclipse.persistence.internal.jpa.querydef.FromImpl.join(FromImpl.java:485)
at org.springframework.data.jpa.repository.query.QueryUtils.getOrCreateJoin(QueryUtils.java:596)
at org.springframework.data.jpa.repository.query.QueryUtils.toExpressionRecursively(QueryUtils.java:524)
at org.springframework.data.jpa.repository.query.JpaQueryCreator$PredicateBuilder.getTypedPath(JpaQueryCreator.java:332)
at org.springframework.data.jpa.repository.query.JpaQueryCreator$PredicateBuilder.build(JpaQueryCreator.java:275)
at org.springframework.data.jpa.repository.query.JpaQueryCreator.toPredicate(JpaQueryCreator.java:180)
at org.springframework.data.jpa.repository.query.JpaQueryCreator.create(JpaQueryCreator.java:109)
at org.springframework.data.jpa.repository.query.JpaQueryCreator.create(JpaQueryCreator.java:49)
at org.springframework.data.repository.query.parser.AbstractQueryCreator.createCriteria(AbstractQueryCreator.java:109)
at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:88)
at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:73)
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery$QueryPreparer.<init>(PartTreeJpaQuery.java:118)
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery$CountQueryPreparer.<init>(PartTreeJpaQuery.java:241)
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:68)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:103)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:214)
原因:java.lang.ClassCastException:org.eclipse.persistence.internal.jpa.metamodel.SingularAttributeImpl无法转换为javax.persistence.metamodel.PluralAttribute
位于org.eclipse.persistence.internal.jpa.querydef.frompl.join(frompl.java:485)
位于org.springframework.data.jpa.repository.query.QueryUtils.getOrCreateJoin(QueryUtils.java:596)
位于org.springframework.data.jpa.repository.query.QueryUtils.toexpressionRecursely(QueryUtils.java:524)
位于org.springframework.data.jpa.repository.query.JpaQueryCreator$PredicateBuilder.getTypedPath(JpaQueryCreator.java:332)
位于org.springframework.data.jpa.repository.query.JpaQueryCreator$PredicateBuilder.build(JpaQueryCreator.java:275)
位于org.springframework.data.jpa.repository.query.JpaQueryCreator.toPredicate(JpaQueryCreator.java:180)
位于org.springframework.data.jpa.repository.query.JpaQueryCreator.create(JpaQueryCreator.java:109)
位于org.springframework.data.jpa.repository.query.JpaQueryCreator.create(JpaQueryCreator.java:49)
位于org.springframework.data.repository.query.parser.AbstractQueryCreator.createCriteria(AbstractQueryCreator.java:109)
位于org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:88)
位于org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:73)
位于org.springframework.data.jpa.repository.query.PartTreeJpaQuery$QueryPreparer(PartTreeJpaQuery.java:118)
位于org.springframework.data.jpa.repository.query.PartTreeJpaQuery$CountQueryPreparer(PartTreeJpaQuery.java:241)
位于org.springframework.data.jpa.repository.query.PartTreeJpaQuery(PartTreeJpaQuery.java:68)
位于org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:103)
位于org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:214)
我尝试了以下内容和教程,但没有帮助我认为您的问题在于Spring数据版本和您使用的EclipseLink版本之间不兼容 SpringBoot中对Eclipselink的支持似乎不好。
在spring引导依赖项的pom.xml中:
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.4.0.RELEASE</version>
但是没有关于日食的信息。同样,在
spring boot starter数据jpa
pom中,您对dependencies
标记中的hibernate core
有直接依赖关系:
<dependencies>
...
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jta_1.1_spec</artifactId>
</exclusion>
</exclusions>
</dependency>
...
<dependencies>
但由于缺少此功能,您必须在pom.xml中指定Eclipslink的版本:
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.6.3</version>
</dependency>
org.eclipse.persistence
日食
2.6.3
在您的情况下,猜测Eclipselink的哪个版本与1.4 spring引导版本兼容可能会比较复杂,因为您的教程使用的是1.3.2 spring引导版本
为了解决您的问题,我建议您尝试使用与教程中相同的版本(EclipseLink和Spring Boot),或者使用SpringBoot和EclipseLink的任何工作应用程序,以检查是否存在版本兼容性问题。如果可以的话,那么如果你想更新你的Spring Boot或EclipseLink版本,或者两者都更新,你必须做一些测试来验证Spring Boot和EclipseLink版本之间的成功结合。我成功了,但是发现了太多问题和不兼容,所以我回到了hibernate
<properties>
...
<hibernate.version>5.0.9.Final</hibernate.version>
<hibernate-validator.version>5.2.4.Final</hibernate-validator.version>
...
</properties>
<dependencies>
...
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jta_1.1_spec</artifactId>
</exclusion>
</exclusions>
</dependency>
...
<dependencies>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.6.3</version>
</dependency>