Results 1 to 4 of 4

Thread: OpenJPA2 + Spring ORM 3.0: should import javax.persistence.criteria too?

  1. #1
    Join Date
    Mar 2005
    Location
    Hong Kong
    Posts
    19

    Default OpenJPA2 + Spring ORM 3.0: should import javax.persistence.criteria too?

    Hi,

    Was playing around a combination of OpenJPA 2.0.0 M2 with Spring 3.0.0.M3, made a OSGi-based test environment with Pax Exam.

    Everything is smooth until I want to take advantage of autowiring EntityManager fields annotated with @PersistenceContext.

    This is my XML config for the context:

    Code:
    <?xml version="1.0" encoding="us-ascii" ?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:osgi="http://www.springframework.org/schema/osgi"
    	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	   xmlns:context="http://www.springframework.org/schema/context"
    	   xmlns:tx="http://www.springframework.org/schema/tx"
    	   xsi:schemaLocation="http://www.springframework.org/schema/beans
    	   http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-2.5.xsd
           http://www.springframework.org/schema/osgi
           http://www.springframework.org/schema/osgi/spring-osgi.xsd
           http://www.springframework.org/schema/tx
           http://www.springframework.org/schema/tx/spring-tx.xsd">
    
    	<osgi:reference id="transactionManager"
    	 cardinality="1..1"
    	 interface="org.springframework.transaction.PlatformTransactionManager" />
    
    	<osgi:reference id="entityManagerFactory"
    	 cardinality="1..1"
    	 interface="javax.persistence.EntityManagerFactory" />
    
    	<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
    
    	<context:annotation-config />
    
    	<tx:annotation-driven transaction-manager="transactionManager"/>
    
    	<bean class="JpaGenericDaoImpl">
    		<constructor-arg index="0" value=courier.objects.Courier" />
    	</bean>
    
    	<osgi:service interface="courier.managers.CourierManager" id="CourierManager">
    		<bean id="courierManager" class="courier.managers.CourierManagerImpl" />
    	</osgi:service>
    
    </beans>
    Inside JpaGenericDaoImpl above contains such annotated field.

    Code:
    @PersistenceContext
    private EntityManager entityManager;
    However when I ran the test I got a ClassNotFoundException, complaining javax.persistence.criteria.CriteriaQuery was not found.

    When I manually added the package import back to Spring ORM's jar:

    Code:
    javax.persistence.criteria;version="[2.0.0, 3.0.0)";resolution:=optional
    Everything is fine.

    I suppose Spring ORM's jar should add such import so I don't need to patch the jar?

    rgds,
    Raymond

  2. #2
    Join Date
    Aug 2004
    Posts
    1,110

    Default

    Looks like there is a transitive dependency missing somewhere. Since Spring is still based on JPA 1.0 and is not using or referencing that class I don't see why we should add the import it to the Spring ORM jar manifest. Maybe it should be added to one of the OpenJPA jars you are using or to your own manifest. Have you tried that?

    -Thomas
    Thomas Risberg
    SpringSource by Pivotal
    http://www.springsource.org

  3. #3
    Join Date
    Mar 2005
    Location
    Hong Kong
    Posts
    19

    Default

    That's because I was told Spring 3.0 will eventually supports JPA spec 2.0, so I think it's where I should ask for help...

    Anyway, for the details of the exception:
    Code:
    Exception in thread "SpringOsgiExtenderThread-2" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'JpaGenericDaoImpl#0': Injection of persistence fields failed; nested exception is java.lang.NoClassDefFoundError: javax.persistence.criteria.CriteriaQuery
    	at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessAfterInstantiation(PersistenceAnnotationBeanPostProcessor.java:310)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:961)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:475)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:412)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:383)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:276)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:273)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:175)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:485)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:716)
    	at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:69)
    	at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:355)
    	at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
    	at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320)
    	at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:136)
    	at java.lang.Thread.run(Thread.java:636)
    Caused by: java.lang.NoClassDefFoundError: javax.persistence.criteria.CriteriaQuery
    	at $Proxy21.<clinit>(Unknown Source)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
    	at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:605)
    	at org.springframework.orm.jpa.SharedEntityManagerCreator.createSharedEntityManager(SharedEntityManagerCreator.java:114)
    	at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.resolveEntityManager(PersistenceAnnotationBeanPostProcessor.java:609)
    	at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.getResourceToInject(PersistenceAnnotationBeanPostProcessor.java:571)
    	at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:180)
    	at org.springframework.beans.factory.annotation.InjectionMetadata.injectFields(InjectionMetadata.java:105)
    	at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessAfterInstantiation(PersistenceAnnotationBeanPostProcessor.java:307)
    	... 17 more
    OpenJPA2's bundle does has the import, and I also added this import to the bundle containing JpaGenericDaoImpl and the bundle containing CourierManagerImpl above, but still no avail.

  4. #4
    Join Date
    Aug 2004
    Posts
    1,110

    Default

    Spring 3.0 might have limited support for some JPA 2.0 features but full support will be in 3.1 - follow this JIRA issue for more detail.
    Thomas Risberg
    SpringSource by Pivotal
    http://www.springsource.org

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •