开发者

Can I use the current release of Unitils (3.1) with JPA 2.0?

Using Hibernate EntityManager 3.5.3-Final together with Unitils 3.1 results in:

unitilsAfterTestTearDown(com.unifiedpost.payments.model.TestAccount)  Time elapsed: 0.02 sec  <<< FAILURE!
java.lang.AbstractMethodError: org.springframework.orm.jpa.persistenceunit.SpringPersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:621)
        at org开发者_如何学编程.unitils.orm.jpa.util.provider.hibernate.UnitilsHibernatePersistenceProvider.createContainerEntityManagerFactory(UnitilsHibernatePersistenceProvider.java:47)
        at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:227)
        at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:281)
        at org.unitils.orm.jpa.util.JpaEntityManagerFactoryLoader.createEntityManagerFactoryBean(JpaEntityManagerFactoryLoader.java:77)

This is also reported in: http://jira.unitils.org/browse/UNI-201


The reason is that unitils-orm depends on a 2.5.x release of Spring, which is not JPA2 ready yet.

[INFO] +- org.unitils:unitils-testng:jar:3.1:test
[INFO] +- org.unitils:unitils-orm:jar:3.1:test
[INFO] |  +- org.unitils:unitils-spring:jar:3.1:test
[INFO] |  |  +- org.springframework:spring-core:jar:2.5.2:test
[INFO] |  |  +- org.springframework:spring-beans:jar:2.5.2:test
[INFO] |  |  +- org.springframework:spring-test:jar:2.5.2:test
[INFO] |  |  \- org.springframework:spring-tx:jar:2.5.2:test

See also:

  • http://jira.springframework.org/browse/SPR-6408
  • http://jira.springframework.org/browse/SPR-6705

You have 2 workaround options:

(1) Patch Unitils:

  • Checkout Unitils (http://www.unitils.org/source-repository.html)
  • Fix the root pom: Make it depend on a 3.0.1.RELEASE (or higher)
  • Build a release locally
  • Use this as your new Unitils package
<properties>
    <spring.version>3.0.3.RELEASE</spring.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

(2) Include a patched MutablePersistenceUnitInfo

  • Duplicate Spring MutablePersistenceUnitInfo in your project (and make sure it preceeds the legacy Spring version in the classpath)
  • Add the missing methods to it.
@Override
public String getPersistenceXMLSchemaVersion() {
    return "1.0";
}

@Override
public SharedCacheMode getSharedCacheMode() {
    return SharedCacheMode.NONE;
}

@Override
public ValidationMode getValidationMode() {
    return ValidationMode.NONE;
}

[Answered myself for later reference]


Also not a direct answer to the original question, but the trunk version (4.0-SNAPSHOT) has a Spring 3.0 dependency. Under the hood the JPA support will be re-engineered to use Spring (1).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜