2016-08-20 6 views
3

私はSpring Boot 1.4アプリケーションを持っています。これは、Hibernateの代わりにEclipselinkを使用しようとしています。
今の 、これは私がやったことです:DEPSeclipselink with spring boot

<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> 

私はアプリを実行すると、それが作成JpaBaseConfiguration

@Configuration 
public class JpaConfiguration extends JpaBaseConfiguration { 

protected JpaConfiguration(DataSource dataSource, JpaProperties properties, ObjectProvider<JtaTransactionManager> jtaTransactionManagerProvider) { 
    super(dataSource, properties, jtaTransactionManagerProvider); 
} 

@Bean 
public LocalContainerEntityManagerFactoryBean entityManagerFactory(final EntityManagerFactoryBuilder builder, @Autowired DataSource dataSource) { 
    final LocalContainerEntityManagerFactoryBean ret = builder.dataSource(dataSource) 
      .packages("com.inkdrop.app.domain.models") 
      .persistenceUnit("chathub-perstence-unit") 
      .properties(getVendorProperties()) 
      .build(); 

    return ret; 
} 

@Override 
protected AbstractJpaVendorAdapter createJpaVendorAdapter() { 
    return new EclipseLinkJpaVendorAdapter(); 
} 

@Override 
protected Map<String, Object> getVendorProperties() { 
    return Collections.singletonMap("eclipselink.weaving", "false"); 
} 

設定された追加されましたEclipseLinkの

<dependency> 
    <groupId>org.eclipse.persistence</groupId> 
    <artifactId>eclipselink</artifactId> 
    <version>2.6.3</version> 
</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) 

私はthisthisチュートリアルを以下しようとしたが、

答えて

2

を助けていなかった私は、あなたの問題は春データのバージョンと使用するEclipseLinkのバージョン間の互換性だと思います。

SpringBootでのEclipselinkサポートが悪いようです。
春ブート依存関係ののpom.xmlで :propertiesタグで

<groupId>org.springframework.boot</groupId> 
<artifactId>spring-boot-dependencies</artifactId> 
<version>1.4.0.RELEASE</version> 

、あなたが見ることができます:

<properties> 
... 
<hibernate.version>5.0.9.Final</hibernate.version> 
<hibernate-validator.version>5.2.4.Final</hibernate-validator.version> 
... 
</properties> 

が、EclipseLinkはほぼゼロの情報。

<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> 

が、dependenciesManagementタグでEclipseLinkのための依存関係のない:同じように
は、spring-boot-starter-data-jpaポンポンで、あなたはdependenciesタグでhibernate-coreのための直接の依存関係を持っています。

<dependency> 
    <groupId>org.eclipse.persistence</groupId> 
    <artifactId>eclipselink</artifactId> 
</dependency> 

しかし、この機能が欠落しているとして、あなたはのバージョンを指定する必要があります。projetsこのように、要求に応じて、現在の春のブートバージョンと互換性のEclipseLinkのバージョンを使用することは、道を与えている可能性があるので、それは残念ですあなたのpom.xmlでEclipslink:あなたのケースでは

<dependency> 
    <groupId>org.eclipse.persistence</groupId> 
    <artifactId>eclipselink</artifactId> 
    <version>2.6.3</version> 
</dependency> 

、あなたのチュートリアルでは、1.3.2春のブートバージョンを使用するため、1.4春のブートバージョンと互換性があるのEclipseLinkのバージョンを推測するために複雑になることがあります。

問題を解決するには、チュートリアルやSpringBootとEclipseLinkを使用しているバージョンと互換性の問題があるかどうかを確認するために、同じバージョン(EclipseLinkとSpring Boot)を試してみることをおすすめします。
もし、あなたがSpringBootまたはEclipseLinkのバージョン、あるいはその両方を更新したいのであれば、SpringBootとEclipseLinkのバージョンの間の勝利の組み合わせを検証するためのテストを行う必要があります。

+0

私はそれを動作させましたが、非常に多くの問題と非互換性があり、私はちょうど冬眠に戻りました –