Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Gemini » Problem with Gemini JPA & Spring Data JPA(The EM's returned meta model is null with Gemini JPA)
Problem with Gemini JPA & Spring Data JPA [message #1009748] Fri, 15 February 2013 16:23 Go to next message
Simon Watson is currently offline Simon Watson
Messages: 30
Registered: September 2011
Member
I'm struggling to understand a problem I'm seeing with Spring Data JPA when I try and run a test with Gemini JPA.
The getMetamodel() method of EntityManagerFactory returns null, causing an exception within SD JPA. If I run my test outside of the OSGi server (Virgo) using a LocalContainerEntityManagerFactoryBean, everything works fine.

I can also create a working OSGi bundle which contains a manually created DAO (without Spring Data JPA involved) with the EM provided by Gemini JPA. But, for some reason, I can't combine the two approaches and I've been tearing my hair out trying to understand what's going on.

When testing with the local EM I didn't have any metamodel classes in my project (I'm not working on anything of my own that requires them) and things worked. I've since generated these classes within my persistence unit (separate bundle) but it hasn't resolved the issue with Spring Data JPA.

I'm using Virgo 3.6, and Gemini JPA 1.1. with Gemini DBAccess and MySQL.

Can anyone suggest how I can debug this further?


Here's the error from Virgo:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testDAO': Injection of persistence dependencies failed; nested exception is java.lang.IllegalArgumentException: JPA Metamodel must not be null!
	at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:342)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
	at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:60)
	at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:325)
	at org.eclipse.gemini.blueprint.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
	at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:290)
	at org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:137)
	at org.eclipse.virgo.kernel.agent.dm.ContextPropagatingTaskExecutor$2.run(ContextPropagatingTaskExecutor.java:95)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
	at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.IllegalArgumentException: JPA Metamodel must not be null!
	at org.springframework.util.Assert.notNull(Assert.java:112)
	at org.springframework.data.jpa.mapping.JpaMetamodelMappingContext.<init>(JpaMetamodelMappingContext.java:47)
	at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.setEntityManager(JpaRepositoryFactoryBean.java:50)
	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.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:159)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
	at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:339)
	... 18 common frames omitted


Here's my bundle-context.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:osgi="http://www.springframework.org/schema/osgi"
	xmlns:jpa="http://www.springframework.org/schema/data/jpa"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd
		http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
		">

    <osgi:reference id="entityManagerFactory" interface="javax.persistence.EntityManagerFactory" filter="(osgi.unit.name=TestPU)" /> 
    
	<jpa:repositories base-package="foo.test.dao"/>
	
	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
       <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>
    
	<tx:annotation-driven transaction-manager="transactionManager" />
	
	<bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect"/>
	
	<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>

</beans>


Do I need to declare a "org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" bean? I've tried with and without but it doesn't change the error I'm getting.

Here's my bundle's manifest, showing its dependencies:

Manifest-Version: 1.0
Bundle-Version: 1.0.0
Bundle-Name: Test DAO Bundle
Bundle-ManifestVersion: 2
Import-Package: 
 foo.test.model,
 javax.sql,
 org.aopalliance.aop;version="1.0.0"
Bundle-SymbolicName: foo.test.dao
Import-Bundle: 
 org.springframework.aop;version="[3.1.0.RELEASE,3.1.0.RELEASE]",
 org.springframework.aop;version="[3.1.0.RELEASE,3.1.0.RELEASE]",
 org.springframework.orm;version="[3.1.0.RELEASE,3.1.0.RELEASE]",
 org.springframework.transaction;version="[3.1.0.RELEASE,3.1.0.RELEASE]",
 org.springframework.context;version="[3.1.0.RELEASE,3.1.0.RELEASE]",
 org.springframework.beans;version="[3.1.0.RELEASE,3.1.0.RELEASE]",
 org.springframework.core;version="[3.1.0.RELEASE,3.1.0.RELEASE]",
 org.springframework.jdbc;version="[3.1.0.RELEASE,3.1.0.RELEASE]",
 org.springframework.data.core;version="[1.5.0.RELEASE,1.5.0.RELEASE]",
 org.springframework.data.jpa;version="[1.3.0.RELEASE,1.3.0.RELEASE]",
 javax.persistence;version="[2.0.4.v201112161009,2.0.4.v201112161009]"
Re: Problem with Gemini JPA & Spring Data JPA [message #1009783 is a reply to message #1009748] Fri, 15 February 2013 17:54 Go to previous messageGo to next message
Simon Watson is currently offline Simon Watson
Messages: 30
Registered: September 2011
Member
An update on this after some more testing. It definitely seems the metamodel is missing when using an EntityManagerFactory provided by Gemini JPA (via OSGi). When I use a local entitymanagerfactory, the metamodel is available. Can anyone enlighten me as to why this is?
Re: Problem with Gemini JPA & Spring Data JPA [message #1010520 is a reply to message #1009783] Sun, 17 February 2013 15:01 Go to previous messageGo to next message
Michael Keith is currently offline Michael Keith
Messages: 215
Registered: July 2009
Senior Member
Hi Simon,

Sounds like it could be a bug. Could you please enter a bug report and I will take a look at it?

Thanks.

-Mike
Re: Problem with Gemini JPA & Spring Data JPA [message #1021597 is a reply to message #1010520] Wed, 20 March 2013 11:16 Go to previous message
Simon Watson is currently offline Simon Watson
Messages: 30
Registered: September 2011
Member
Another update on this - adding metamodel classes to our PU bundle (in order to use criteria API) causes this problem to disappear. I will file a bug report.
Previous Topic:[Gemini-naming] Referecing an Osgi service with filter fails
Next Topic:Gemini Blueprint 2.0.0.M02
Goto Forum:
  


Current Time: Thu Oct 23 03:55:44 GMT 2014

Powered by FUDForum. Page generated in 0.01720 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software