[kf-users] Spring JPA issue in OSGI

Bellan Saravanan sarbx at hotmail.com
Wed Jul 23 12:33:03 CEST 2008


Not sure why it does not work in your case, but this is what we have been doing and it works fine in KF,
 
We have one bundle called db-config-bundle which exposes the EntityManagerFactory as a OSGI service as follows,
 
[code]
 
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:dataSource-ref="apacheDBCPDataSource">
...
</bean>
 
<osgi:service id="entityManagerFactoryOsgi" ref="entityManagerFactory"
interface="javax.persistence.EntityManagerFactory" />
[/code]
and in the service/dao bundle,
 
[code]
<osgi:reference id="entityManagerFactoryOsgi"
interface="javax.persistence.EntityManagerFactory" />
 
and inject the corresponding EntityManager using,
 
@PersistenceContext
private EntityManager em;
[/code]
 
Even in the single bundle case if you just use the @PersistentContext or @PersistentUnit annotation to inject the EntityManager or the Factory it should work fine.




Date: Wed, 23 Jul 2008 10:02:15 +0000From: sukhdev_hbti at rediffmail.comTo: knopflerfish-users at knopflerfish.orgSubject: [kf-users] Spring JPA issue in OSGI
Hi,I made a spring based application to access mysql database using JPA.  Application is working fine as a standalone. But when i deploy this as a bundle in knopflerfish OSGI it does not work. Following is the execption it produces. I have also attached xml file.Exception in thread "SpringOsgiExtenderThread-163" [stderr] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testService' defined in URL [bundle://198/META-INF/spring/spring.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean] to required type [javax.persistence.EntityManagerFactory] for property 'entityManagerFactory'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean] to required type [javax.persistence.EntityManagerFactory] for property 'entityManagerFactory': no matching editors or conversion strategy found[stderr]      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:478)[stderr]      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)[stderr]      at java.security.AccessController.doPrivileged(Native Method)[stderr]      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)[stderr]      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)[stderr]      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:220)[stderr]      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)[stderr]      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)[stderr]      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)[stderr]      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)[stderr]      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)[stderr]      at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:271)[stderr]      at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:142)[stderr]      at java.lang.Thread.run(Thread.java:595)[stderr] Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean] to required type [javax.persistence.EntityManagerFactory] for property 'entityManagerFactory'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean] to required type [javax.persistence.EntityManagerFactory] for property 'entityManagerFactory': no matching editors or conversion strategy found[stderr]      at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:391)[stderr]      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1287)[stderr]      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1248)[stderr]      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1008)[stderr]      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:470)[stderr]      ... 13 more[stderr] Caused by: java.lang.IllegalArgumentException: Cannot convert value of type [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean] to required type [javax.persistence.EntityManagerFactory] for property 'entityManagerFactory': no matching editors or conversion strategy found[stderr]      at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:219)[stderr]      at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:138)[stderr]      at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:386)[stderr]      ... 17 morePlease help me on this.RegardsSukhdev




_________________________________________________________________
Stay in touch when you're away with Windows Live Messenger.
http://www.windowslive.com/messenger/overview.html?ocid=TXT_TAGLM_WL_messenger2_072008
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.knopflerfish.org/pipermail/knopflerfish-users/attachments/20080723/0618acba/attachment-0001.html 


More information about the Knopflerfish-users mailing list