Back Forum Reply New

Jpa 2.0

Hi:

I have an application with jpa2.0 and Spring jpa support with the next configuration:

Spring context:

Code:

lt;!-- jpa entity manager factory --gt;
lt;bean id=quot;entityManagerFactoryquot; class=quot;org..orm.jpa.LocalContainerEntityManagerFactoryBeanquot;gt;
lt;property name=quot;dataSourcequot; ref=quot;dataSourcequot; /gt;
lt;property name=quot;jpaVendorAdapterquot;gt;

lt;!-- jpa vendor --gt;
lt;bean class=quot;org..orm.jpa.vendor.OpenJpaVendorAdapterquot;gt;
lt;property name=quot;showSqlquot; value=quot;truequot; /gt;
lt;property name=quot;generateDdlquot; value=quot;truequot; /gt;
lt;property name=quot;databasequot; value=quot;MYSQLquot; /gt;
lt;/beangt;
lt;/propertygt;
lt;property name=quot;jpaPropertiesquot;gt;
lt;propsgt;
lt;prop key=quot;openjpa.jdbc.SynchronizeMappingsquot;gt;buildSchema(SchemaAction='add',ForeignKeys=true)lt;/propgt;
lt;prop key=quot;openjpa.jdbc.MappingDefaultsquot;gt;ForeignKeyDeleteAction=restrict, JoinForeignKeyDeleteAction=restrictlt;/propgt;
lt;/propsgt;
lt;/propertygt;
lt;/beangt;
Maven dependencies:

Code:
lt;dependencygt;
lt;groupIdgt;org.lt;/groupIdgt;
lt;artifactIdgt;spring-jpalt;/artifactIdgt;
lt;versiongt;2.0.8lt;/versiongt;
lt;/dependencygt;
lt;dependencygt;
lt;groupIdgt;org.apache.openjpalt;/groupIdgt;
lt;artifactIdgt;openjpalt;/artifactIdgt;
lt;versiongt;2.0.0-SNAPSHOTlt;/versiongt;
lt;/dependencygt;
When I launch my application in Glassfish all work fine (after some tunning), but, when I launch a JUnit test I have the next exception;Code:
org..beans.factory.BeanCreationException: Error creating bean with name 'org..dao.annotation.PersistenceExceptionTranslationPostProcessor#0' defined in class path resource [testDaoContext.xml]: Initialization of bean failed; nested exception is org..beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [testDaoContext.xml]: Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org..orm.jpa.persistenceunit.SpringPersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
at org..beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:478)
at org..beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org..beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org..beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org..beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:220)
at org..beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org..beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org..beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org..context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:881)
at org..context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:597)
at org..context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:366)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org..test.jpa.AbstractJpaTests.runBare(AbstractJpaTests.java:229)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:76)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org..beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [testDaoContext.xml]: Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org..orm.jpa.persistenceunit.SpringPersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
at org..beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1336)
at org..beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:471)
at org..beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org..beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org..beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org..beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:220)
at org..beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org..beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org..beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org..beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:308)
at org..beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors(BeanFactoryUtils.java:270)
at org..dao.support.PersistenceExceptionTranslationInterceptor.detectPersistenceExceptionTranslators(PersistenceExceptionTranslationInterceptor.java:122)
at org..dao.support.PersistenceExceptionTranslationInterceptor.lt;initgt;(PersistenceExceptionTranslationInterceptor.java:78)
at org..dao.annotation.PersistenceExceptionTranslationAdvisor.lt;initgt;(PersistenceExceptionTranslationAdvisor.java:70)
at org..dao.annotation.PersistenceExceptionTranslationPostProcessor.setBeanFactory(PersistenceExceptionTranslationPostProcessor.java:97)
at org..beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1324)
at org..beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:471)
... 29 more
Caused by: java.lang.AbstractMethodError: org..orm.jpa.persistenceunit.SpringPersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
at org.apache.openjpa.persistence.PersistenceUnitInfoImpl.toOpenJPAProperties(PersistenceUnitInfoImpl.java:460)
at org.apache.openjpa.persistence.PersistenceProductDerivation.load(PersistenceProductDerivation.java:185)
at org.apache.openjpa.persistence.PersistenceProviderImpl.createContainerEntityManagerFactory(PersistenceProviderImpl.java:125)
at org.apache.openjpa.persistence.PersistenceProviderImpl.createContainerEntityManagerFactory(PersistenceProviderImpl.java:55)
at org..orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:218)
at org..orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:251)
at org..beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1367)
at org..beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1333)
... 46 more
The problem is that Spring uses SpringPersistenceUnitInfo wich implements javax.persistence.spi.PersistenceUnitInfo from jpa1. However, I'm using Jpa2, so when the application is going to invoke the method PersistenceUnitInfo.getValidationMode() (which is only in version of jpa2), it crashes.

I suppose this is a question of configuration but I dont realize where is my mistake. I think that Spring should delegate in the class org.apache.openjpa.persistence.PersistenceUnitInfo  Impl from the  openjpa-2.0.0-SNAPSHOT.jar, but I dont know how to do that.

Could anybody help me with this issue?
I hope I wrote enough information about this error.


Originally Posted by classmundo...

I suppose this is a question of configuration but I dont realize where is my mistake. I think that Spring should delegate in the class org.apache.openjpa.persistence.PersistenceUnitInfo  Impl from the  openjpa-2.0.0-SNAPSHOT.jar, but I dont know how to do that.

Just make sure that jpa2 jar is mentioned at the application classpath before jpa1 jar.

Also notice that there is no FULL jpa 2.0 support in spring versions prior to 3.0. So you might run into issues here. For full JPA 2.0 support you will have to wait for Spring 3.0 (check this JIRA issue). Next to that until the JSR is final there is no garantuee that it will (keep working). Full and certified support is scheduled for Spring 3.1.


Originally Posted by denis.zhdanovJust make sure that jpa2 jar is mentioned at the application classpath before jpa1 jar.

There is not jpa1 in the classpath. Anyway, I will investigate a little bit more because in glassfish is working, so It's possible to be a classpath problem.

Hi everyone,

i'm facing the same problem at the moment. I'm also investigating what is wrong, I can tell you guys that it works when you deploy it on a Liferay server with Tomcat 6.0. I'll update you guys when I know more about the difference which is causing this.

(edit)I'm using Spring 3.0.0.M3(/edit)

Hi,

I have the same issue when trying to use latest Hibernate with Spring 3.0.0.RELEASE.

I'll double check but I'm nearly certain I don't have jpa1 in the classpath.

See: browse/SPR-6408

Also getting it with OpenJPA1.2.1Code:
Caused by: java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
at org.apache.openjpa.persistence.PersistenceUnitInfoImpl.toOpenJPAProperties(PersistenceUnitInfoImpl.java:457)
at org.apache.openjpa.persistence.PersistenceProductDerivation.load(PersistenceProductDerivation.java:313)
at org.apache.openjpa.persistence.PersistenceProviderImpl.createContainerEntityManagerFactory(PersistenceProviderImpl.java:158)
at org.apache.openjpa.persistence.PersistenceProviderImpl.createContainerEntityManagerFactory(PersistenceProviderImpl.java:62)
at org..orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225)
at org..orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:308)
at ca.BidSpec.emall.application.BidspecContextConfiguration.entityManagerFactory(BidspecContextConfiguration.java:139)
at ca.BidSpec.emall.application.BidspecContextConfiguration$$EnhancerByCGLIB$$7378aded.CGLIB$entityManagerFactory$6(lt;generatedgt;)
at ca.BidSpec.emall.application.BidspecContextConfiguration$$EnhancerByCGLIB$$7378aded$$FastClassByCGLIB$$80b293df.invoke(lt;generatedgt;)
at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:215)
at org..context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:210)
at ca.BidSpec.emall.application.BidspecContextConfiguration$$EnhancerByCGLIB$$7378aded.entityManagerFactory(lt;generatedgt;)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org..beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:146)
... 75 moreOkay the issue was resolved by upgrading to Spring 3.0.1 and OpenJPA2.0.0-beta 2.
Also had to make sure the OpenJPA jar was up near the top of the classpath as something else is drawing in the 1.2X version of the jar. If anyone is using the maven openjpa plugin there is a config setting to set the OpenJPA jar version that if not set will default to using 1.2X. This should be more clear as it is buried inside a deep page but that is that project issue to resolve.

Thnaks for all the help

Phill


Originally Posted by springin2actionOkay the issue was resolved by upgrading to Spring 3.0.1 and OpenJPA2.0.0-beta 2.
Also had to make sure the OpenJPA jar was up near the top of the classpath as something else is drawing in the 1.2X version of the jar. If anyone is using the maven openjpa plugin there is a config setting to set the OpenJPA jar version that if not set will default to using 1.2X. This should be more clear as it is buried inside a deep page but that is that project issue to resolve.

Thnaks for all the help

Phill

I've been facing the same problem and haven't found a solution. Could you, please, help me by publishing (or sending me) the spring related parts of your web.xml and faces-config.xml files ? I'm trying to use Spring 3.0.1 and OpenJPA2.0.0-beta 2 after failing to get Spring-2.5.6 and OpenJPA-1.2 to work.
My application is a JSF2 one : I'm using mojarra-2.0.2-FCS, icefaces-2.0.0-alpha2, myfaces-orchestra-core20-1.5-SNAPSHOT, openJpa-2 and Spring.

regards !

ebm/
¥
Back Forum Reply New