Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Virgo » How to inject EntityManager in each bundle?
How to inject EntityManager in each bundle? [message #633047] Fri, 15 October 2010 08:16 Go to next message
guofeng zhang is currently offline guofeng zhangFriend
Messages: 49
Registered: July 2009
Member
I have one main bundle that loads the persistence.xml file and create an entityManagerFactory using LocalContainerEntityManagerFactoryBean in the context file.

I hope a class in any other bundles could have EntityManager injected when @PersistenceContext is used for the class.

(1) I do not know how to publish javax.persistence.EntityManagerFactory in the context. If I publish EntityManagerFactoryInfo as a service in the main bundle, it does not work for other bundles.


(2) Is there any built-in support for it in Virgo (by SpringFramework)?

Thanks

Re: How to inject EntityManager in each bundle? [message #633083 is a reply to message #633047] Fri, 15 October 2010 10:17 Go to previous messageGo to next message
guofeng zhang is currently offline guofeng zhangFriend
Messages: 49
Registered: July 2009
Member
Write a class to implement ApplicationContextAware to publish javax.persistence.EntityManagerFactory seems to work.

Is there built-in support in SpringFramework for it?
Re: How to inject EntityManager in each bundle? [message #633093 is a reply to message #633083] Fri, 15 October 2010 10:52 Go to previous messageGo to next message
Dmitry Sklyut is currently offline Dmitry SklyutFriend
Messages: 276
Registered: January 2010
Senior Member
There are at least 3 ways to go about it:

1. You can publish LocalContainerEntityManagerFactoryBean.
This works well if you have a Spring client on the other side

2. You can publish EntityManagerFactory created by the LocalContainerEntityManagerFactoryBean

3. You can look at gemini jpa (http://www.eclipse.org/gemini/jpa/)

Are you clients in other bundles use Spring for wiring and injection?

If so - you should go with option #1 and publish that puppy with

<osgi:service auto-export="all-classes" context-class-loader="service-provider" ....

Give that a try. I would also recommend publishing PlatformTransaction manager from same bundle to get Spring managed transactions without having to set-up a separate transaction manager in each bundle. If you have a transaction spanning multiple service calls from different bundles - you must have a single transaction manager.
Re: How to inject EntityManager in each bundle? [message #633162 is a reply to message #633093] Fri, 15 October 2010 14:27 Go to previous messageGo to next message
Dmitry Sklyut is currently offline Dmitry SklyutFriend
Messages: 276
Registered: January 2010
Senior Member
I would like to follow up on the "context-class-loader" property recommendation.

First lets start with how Spring DM deploys services.

All services are deployed (<osgi:service />) and imported (<osgi:reference/>) as proxy.
Spring DM does it for:

1. To manage lifecycle of the beans
2. To give Spring AppContext something concreate to hold to during start up. This allows Spring (static resolution) to work in OSGi (dynamic) environment even if service is not yet deployed in Service registry.
3. To manage TCCL.

By default Spring DM will use TCCL of the client with <osgi:reference />. But sometimes libraries used by the service provider (<osgi:service />) side make some assumptions about TCCL. In those cases it is helpful to managed TCCL. Note (from Spring DM docs):
Quote:

context class loader management on the importer and exporter
Spring DM has the ability to do context class loader management on both the importer and exporter side. Normally, if Spring DM works on both sides, only one side should have this feature enabled. However, if both sides (importer and exporter) take advantage of this capability, the last entity in the call chain will win. This means that the exporter setting, if enabled, will always override the importer setting (whatever that is).




Back to the use case here.

If JPA/Hibernate/ORM solution is used in a scoped plan or a par - there is NO NEED to use TCCL management feature of Spring DM.

When Virgo creates a scoped deployment, TCCL is managed to include all referenced classes from plan/par. Given that, everything ORM tool is using internally can be found with TCCL.

But what about unscoped deployments? This is the use case that I have in the current application. In this situation one can run head first into CNF and other issues. Some ORM tools (ahem Hibernate) want to load everything under the sun through TCCL.

If <osgi:reference /> sets a TCCL to a "client" - than client must have visibility into ALL possible classes that ORM tool might use.

Examples can include:
1. HQL/JPAQL parsing with ANTLR
2. Proxy classes generated by the ORM framework on the fly or with code generation (javasist, cglib, etc)

So if the client only has imports for javax.persistence and does not import any of the framework supporting stuff - you might run into an issue.

This is where switching to service-provider TCCL might help.

This might sound like putting a lipstick on a pig, and basically means that the library you are using is not very OSGi friendly.

Hope this clears up the recommendation a bit.
I believe that recommended way of using ORM in Virgo is to use a scoped deployment. You will be better off in the long run.

Re: How to inject EntityManager in each bundle? [message #633445 is a reply to message #633162] Mon, 18 October 2010 03:44 Go to previous messageGo to next message
guofeng zhang is currently offline guofeng zhangFriend
Messages: 49
Registered: July 2009
Member
Your suggested option #1 is what I want to do and asked here. Following it, javax.persisence.EntityManagerFactory is published successfully.

Thanks for the details. It is very helpful.

Yes, other bundles in our application are all based on Spring for wiring and injection.

Re: How to inject EntityManager in each bundle? [message #633732 is a reply to message #633047] Tue, 19 October 2010 07:31 Go to previous messageGo to next message
guofeng zhang is currently offline guofeng zhangFriend
Messages: 49
Registered: July 2009
Member
The EntityManagerFactory in org.planner.service.jpa bundle is published successfully, but when I tried to access it in other bundle (org.planner.service.m ember.management.impl), I got the following message. It is publihsed by
 <bean id="entityManagerFactory"
	class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
		<property name="dataSource" ref="plannerDataSource" />
		<property name="persistenceUnitName" value="planner" />
                <property name="jpaVendorAdapter" ref="jpaVendorAdapter"/>
                <property name="jpaProperties">
		        <props>
			    <prop key="eclipselink.session.customizer">org.planner.eclipselink.transaction.session.customizer.TransactionSessionCustomizer</prop>
			</props>
		</property>
	</bean>

<osgi:service ref = "entityManagerFactory" auto-export="all-classes" context-class-loader="service-provider" />

That is, the option #1.

If I only changed this part to publish it using option #2 as the following in my application context implementation(in setApplicationContext()) in the jpa bundle:
			String serviceName = javax.persistence.EntityManagerFactory.class.getName() ;
			EntityManagerFactoryInfo emi = (EntityManagerFactoryInfo)appContext.getBean( "entityManagerFactory" ) ;
			Activator.getBundleContext().registerService( serviceName, 
					emi.getNativeEntityManagerFactory(),
					null);

My application works well: save data and load data from the database without problem.

What's the reason? Is it by final classes, or which classes should be imported?

Thanks for assistance.

[2010-10-19 11:01:35.345] region-dm-1 o.s.osgi.service.importer.support.OsgiServiceProxyFactoryBea n Looking for mandatory OSGi service dependency for bean [myTransactionManager] matching filter (objectClass=org.springframework.transaction.PlatformTransac tionManager)
[2010-10-19 11:01:35.345] region-dm-1 o.s.osgi.service.importer.support.OsgiServiceProxyFactoryBea n Found mandatory OSGi service for bean [myTransactionManager]
[2010-10-19 11:01:35.345] region-dm-1 o.s.osgi.service.exporter.support.OsgiServiceFactoryBean Publishing service under classes [{java.io.Serializable, java.lang.reflect.Proxy, javax.persistence.EntityManagerFactory, org.springframework.orm.jpa.EntityManagerFactoryInfo}]
[2010-10-19 11:01:35.345] region-dm-1 .a.d.i.BlueprintEventPostingOsgiBundleApplicationContextList ener Sending event to topic 'org/osgi/service/blueprint/container/GRACE_PERIOD' with properties '{bundle.version=1.0.0.201010191030, bundle=org.planner.service.member.management.impl_1.0.0.2010 10191030 [91], bundle.symbolicName=org.planner.service.member.management.im pl, type=6, timestamp=1287457295345, bundle.id=91}'
[2010-10-19 11:01:35.361] Thread-3 org.eclipse.virgo.kernel.core.internal.BundleStartTracker Handling event 'org.osgi.service.event.Event [topic=org/osgi/service/blueprint/container/GRACE_PERIOD]'
[2010-10-19 11:01:35.361] Thread-3 o.e.v.k.c.internal.blueprint.ApplicationContextDependencyMon itor Service dependency '(objectClass=javax.persistence.EntityManagerFactory) &entityManagerFactory' has been satisfied
[2010-10-19 11:01:35.361] region-dm-1 o.s.o.e.internal.dependencies.startup.DependencyServiceManag er No unsatisfied OSGi service dependencies; completing initialization for OsgiBundleXmlApplicationContext(bundle=org.planner.service.m ember.management.impl, config=osgibundle:/META-INF/spring/*.xml)
[2010-10-19 11:01:35.361] region-dm-1 o.s.osgi.context.support.OsgiBundleXmlApplicationContext Publishing application context as OSGi service with properties {org.springframework.context.service.name=org.planner.servic e.jpa, Bundle-SymbolicName=org.planner.service.jpa, Bundle-Version=1.0.0.201010191059}
[2010-10-19 11:01:35.361] region-dm-1 .a.d.i.BlueprintEventPostingOsgiBundleApplicationContextList ener Sending event to topic 'org/osgi/service/blueprint/container/CREATED' with properties '{bundle.version=1.0.0.201010191059, bundle=org.planner.service.jpa_1.0.0.201010191059 [88], bundle.symbolicName=org.planner.service.jpa, type=1, timestamp=1287457295361, bundle.id=88}'
[2010-10-19 11:01:35.361] Thread-3 org.eclipse.virgo.kernel.core.internal.BundleStartTracker Handling event 'org.osgi.service.event.Event [topic=org/osgi/service/blueprint/container/CREATED]'
[2010-10-19 11:01:35.361] Thread-3 org.eclipse.virgo.kernel.core.internal.BundleStartTracker Recording created application context for bundle 'org.planner.service.jpa_1.0.0.201010191059 [88]'
[2010-10-19 11:01:35.361] start-signalling-3 org.eclipse.virgo.kernel.core.internal.BundleStartTracker Driving signal 'org.eclipse.virgo.kernel.install.artifact.internal.Abstract InstallArtifact$StateMonitorSignal@1cbeebb'
[2010-10-19 11:01:35.361] start-signalling-3 o.e.v.k.i.artifact.internal.bundle.BundleThreadContextManage r Thread context class loader 'KernelBundleClassLoader: [bundle=org.eclipse.virgo.apps.repository-2.1.0.M06-incubati on-synthetic.context_2.1.0.M06-incubation]' pushed and set to 'KernelBundleClassLoader: [bundle=org.planner.service.jpa_1.0.0.201010191059]'
[2010-10-19 11:01:35.361] start-signalling-3 org.eclipse.virgo.medic.eventlog.default DE0005I Started bundle 'org.planner.service.jpa' version '1.0.0.201010191059'.
[2010-10-19 11:01:35.361] start-signalling-3 o.e.v.k.i.artifact.internal.bundle.BundleThreadContextManage r Thread context class loader 'KernelBundleClassLoader: [bundle=org.planner.service.jpa_1.0.0.201010191059]' popped and set to 'KernelBundleClassLoader: [bundle=org.eclipse.virgo.apps.repository-2.1.0.M06-incubati on-synthetic.context_2.1.0.M06-incubation]'
[2010-10-19 11:01:35.376] region-dm-1 o.s.osgi.extender.internal.activator.ContextLoaderListener Application context successfully refreshed (OsgiBundleXmlApplicationContext(bundle=org.planner.service. jpa, config=osgibundle:/META-INF/spring/*.xml))
[2010-10-19 11:01:35.376] region-dm-5 o.s.beans.factory.support.DefaultListableBeanFactory Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBea nFactory @42c747: defining beans [org.springframework.context.weaving.AspectJWeavingEnabler#0 ,loadTimeWeaver,org.springframework.context.annotation.inter nalConfigurationAnnotationProcessor,org.springframework.cont ext.annotation.internalAutowiredAnnotationProcessor,org.spri ngframework.context.annotation.internalRequiredAnnotationPro cessor,org.springframework.context.annotation.internalCommon AnnotationProcessor,org.springframework.context.annotation.i nternalPersistenceAnnotationProcessor,org.springframework.tr ansaction.config.internalTransactionAspect,org.springframewo rk.orm.jpa.support.PersistenceAnnotationBeanPostProcessor#0, helloWorldServiceBean,helloWorldService,transactionManager,e ntityManagerFactory]; root of factory hierarchy
[2010-10-19 11:01:35.408] region-dm-5 o.s.osgi.service.importer.support.OsgiServiceProxyFactoryBea n Looking for mandatory OSGi service dependency for bean [entityManagerFactory] matching filter (objectClass=javax.persistence.EntityManagerFactory)
[2010-10-19 11:01:35.408] region-dm-5 org.springframework.aop.framework.Cglib2AopProxy Unable to proxy method [public final java.lang.ClassLoader $Proxy161.getBeanClassLoader()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
[2010-10-19 11:01:35.408] region-dm-5 org.springframework.aop.framework.Cglib2AopProxy Unable to proxy method [public final java.lang.String $Proxy161.getPersistenceUnitName()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
[2010-10-19 11:01:35.408] region-dm-5 org.springframework.aop.framework.Cglib2AopProxy Unable to proxy method [public final javax.persistence.spi.PersistenceUnitInfo $Proxy161.getPersistenceUnitInfo()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
[2010-10-19 11:01:35.408] region-dm-5 org.springframework.aop.framework.Cglib2AopProxy Unable to proxy method [public final javax.persistence.EntityManager $Proxy161.createEntityManager(java.util.Map)] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
[2010-10-19 11:01:35.408] region-dm-5 org.springframework.aop.framework.Cglib2AopProxy Unable to proxy method [public final javax.persistence.EntityManager $Proxy161.createEntityManager()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
[2010-10-19 11:01:35.408] region-dm-5 org.springframework.aop.framework.Cglib2AopProxy Unable to proxy method [public final javax.persistence.criteria.CriteriaBuilder $Proxy161.getCriteriaBuilder()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
[2010-10-19 11:01:35.408] region-dm-5 org.springframework.aop.framework.Cglib2AopProxy Unable to proxy method [public final javax.persistence.metamodel.Metamodel $Proxy161.getMetamodel()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
[2010-10-19 11:01:35.408] region-dm-5 org.springframework.aop.framework.Cglib2AopProxy Unable to proxy method [public final javax.persistence.PersistenceUnitUtil $Proxy161.getPersistenceUnitUtil()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
[2010-10-19 11:01:35.408] region-dm-5 org.springframework.aop.framework.Cglib2AopProxy Unable to proxy method [public final javax.persistence.spi.PersistenceProvider $Proxy161.getPersistenceProvider()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
[2010-10-19 11:01:35.408] region-dm-5 org.springframework.aop.framework.Cglib2AopProxy Unable to proxy method [public final org.springframework.orm.jpa.JpaDialect $Proxy161.getJpaDialect()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
[2010-10-19 11:01:35.408] region-dm-5 org.springframework.aop.framework.Cglib2AopProxy Unable to proxy method [public final java.lang.Class $Proxy161.getEntityManagerInterface()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
[2010-10-19 11:01:35.408] region-dm-5 org.springframework.aop.framework.Cglib2AopProxy Unable to proxy method [public final javax.sql.DataSource $Proxy161.getDataSource()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
[2010-10-19 11:01:35.408] region-dm-5 org.springframework.aop.framework.Cglib2AopProxy Unable to proxy method [public final javax.persistence.EntityManagerFactory $Proxy161.getNativeEntityManagerFactory()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
[2010-10-19 11:01:35.408] region-dm-5 org.springframework.aop.framework.Cglib2AopProxy Unable to proxy method [public final boolean $Proxy161.equals(java.lang.Object)] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
[2010-10-19 11:01:35.408] region-dm-5 org.springframework.aop.framework.Cglib2AopProxy Unable to proxy method [public final java.lang.String $Proxy161.toString()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
[2010-10-19 11:01:35.408] region-dm-5 org.springframework.aop.framework.Cglib2AopProxy Unable to proxy method [public final int $Proxy161.hashCode()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
[2010-10-19 11:01:35.408] region-dm-5 org.springframework.aop.framework.Cglib2AopProxy Unable to proxy method [public final java.util.Map $Proxy161.getProperties()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
[2010-10-19 11:01:35.408] region-dm-5 org.springframework.aop.framework.Cglib2AopProxy Unable to proxy method [public final void $Proxy161.close()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
[2010-10-19 11:01:35.408] region-dm-5 org.springframework.aop.framework.Cglib2AopProxy Unable to proxy method [public final boolean $Proxy161.isOpen()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
[2010-10-19 11:01:35.408] region-dm-5 org.springframework.aop.framework.Cglib2AopProxy Unable to proxy method [public final javax.persistence.Cache $Proxy161.getCache()] because it is final: All calls to this method via a proxy will be routed directly to the proxy.
[2010-10-19 11:01:35.517] region-dm-5 o.s.o.s.e.support.internal.support.PublishingServiceFactory Cannot create TCCL managed proxy; falling back to the naked object org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class $Proxy161]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class class $Proxy161
at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cg lib2AopProxy.java:212)
at org.springframework.aop.framework.ProxyFactory.getProxy(Prox yFactory.java:112)
at org.springframework.osgi.service.util.internal.aop.ProxyUtil s$1.run(ProxyUtils.java:65)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.osgi.service.util.internal.aop.ProxyUtil s.createProxy(ProxyUtils.java:62)
at org.springframework.osgi.service.exporter.support.internal.s upport.PublishingServiceFactory.createCLLProxy(PublishingSer viceFactory.java:138)
at org.springframework.osgi.service.exporter.support.internal.s upport.PublishingServiceFactory.getService(PublishingService Factory.java:117)
at org.eclipse.osgi.internal.serviceregistry.ServiceUse$1.run(S erviceUse.java:120)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.internal.serviceregistry.ServiceUse.getServ ice(ServiceUse.java:118)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistratio nImpl.getService(ServiceRegistrationImpl.java:447)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.ge tService(ServiceRegistry.java:430)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.g etService(BundleContextImpl.java:667)
at org.springframework.osgi.service.importer.support.internal.s upport.ServiceWrapper.getService(ServiceWrapper.java:99)
at org.springframework.osgi.service.importer.support.internal.a op.ServiceDynamicInterceptor$ServiceLookUpCallback.doWithRet ry(ServiceDynamicInterceptor.java:107)
at org.springframework.osgi.service.importer.support.internal.s upport.RetryTemplate.execute(RetryTemplate.java:83)
at org.springframework.osgi.service.importer.support.internal.a op.ServiceDynamicInterceptor.lookupService(ServiceDynamicInt erceptor.java:430)
at org.springframework.osgi.service.importer.support.internal.a op.ServiceDynamicInterceptor.getTarget(ServiceDynamicInterce ptor.java:415)
at org.springframework.osgi.service.importer.support.internal.a op.ServiceDynamicInterceptor.afterPropertiesSet(ServiceDynam icInterceptor.java:472)
at org.springframework.osgi.service.importer.support.OsgiServic eProxyFactoryBean.createProxy(OsgiServiceProxyFactoryBean.ja va:215)
at org.springframework.osgi.service.importer.support.AbstractSe rviceImporterProxyFactoryBean.getObject(AbstractServiceImpor terProxyFactoryBean.java:86)
at org.springframework.osgi.service.importer.support.OsgiServic eProxyFactoryBean.getObject(OsgiServiceProxyFactoryBean.java :161)
at org.springframework.beans.factory.support.FactoryBeanRegistr ySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySuppo rt.java:142)
at org.springframework.beans.factory.support.FactoryBeanRegistr ySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport .java:102)
at org.springframework.beans.factory.support.AbstractBeanFactor y.getObjectForBeanInstance(AbstractBeanFactory.java:1414)
at org.springframework.beans.factory.support.AbstractBeanFactor y.doGetBean(AbstractBeanFactory.java:245)
at org.springframework.beans.factory.support.AbstractBeanFactor y.getBean(AbstractBeanFactory.java:190)
at org.springframework.orm.jpa.support.PersistenceAnnotationBea nPostProcessor.findDefaultEntityManagerFactory(PersistenceAn notationBeanPostProcessor.java:529)
at org.springframework.orm.jpa.support.PersistenceAnnotationBea nPostProcessor.findEntityManagerFactory(PersistenceAnnotatio nBeanPostProcessor.java:495)
at org.springframework.orm.jpa.support.PersistenceAnnotationBea nPostProcessor$PersistenceElement.resolveEntityManager(Persi stenceAnnotationBeanPostProcessor.java:656)
at org.springframework.orm.jpa.support.PersistenceAnnotationBea nPostProcessor$PersistenceElement.getResourceToInject(Persis tenceAnnotationBeanPostProcessor.java:629)
at org.springframework.beans.factory.annotation.InjectionMetada ta$InjectedElement.inject(InjectionMetadata.java:147)
at org.springframework.beans.factory.annotation.InjectionMetada ta.inject(InjectionMetadata.java:84)
at org.springframework.orm.jpa.support.PersistenceAnnotationBea nPostProcessor.postProcessPropertyValues(PersistenceAnnotati onBeanPostProcessor.java:338)
at org.springframework.beans.factory.support.AbstractAutowireCa pableBeanFactory.populateBean(AbstractAutowireCapableBeanFac tory.java:1074)
at org.springframework.beans.factory.support.AbstractAutowireCa pableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFac tory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCa pableBeanFactory.createBean(AbstractAutowireCapableBeanFacto ry.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactor y$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBe anRegistry.getSingleton(DefaultSingletonBeanRegistry.java:22 2)
at org.springframework.beans.factory.support.AbstractBeanFactor y.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactor y.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBea nFactory.preInstantiateSingletons(DefaultListableBeanFactory .java:580)
at org.springframework.context.support.AbstractApplicationConte xt.finishBeanFactoryInitialization(AbstractApplicationContex t.java:895)
at org.springframework.osgi.context.support.AbstractDelegatedEx ecutionApplicationContext.access$1600(AbstractDelegatedExecu tionApplicationContext.java:69)
at org.springframework.osgi.context.support.AbstractDelegatedEx ecutionApplicationContext$4.run(AbstractDelegatedExecutionAp plicationContext.java:355)
at org.springframework.osgi.util.internal.PrivilegedUtils.execu teWithCustomTCCL(PrivilegedUtils.java:85)
at org.springframework.osgi.context.support.AbstractDelegatedEx ecutionApplicationContext.completeRefresh(AbstractDelegatedE xecutionApplicationContext.java:320)
at org.springframework.osgi.extender.internal.dependencies.star tup.DependencyWaiterApplicationContextExecutor$CompleteRefre shTask.run(DependencyWaiterApplicationContextExecutor.java:1 32)
at org.eclipse.virgo.kernel.agent.dm.ContextPropagatingTaskExec utor$2.run(ContextPropagatingTaskExecutor.java:95)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Threa dPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoo lExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.IllegalArgumentException: Cannot subclass final class class $Proxy161
at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer.java:446)
at net.sf.cglib.transform.TransformingClassGenerator.generateCl ass(TransformingClassGenerator.java:33)
at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultG eneratorStrategy.java:25)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClas sGenerator.java:216)
at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:285)
at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cg lib2AopProxy.java:200)
... 51 common frames omitted

Re: How to inject EntityManager in each bundle? [message #633735 is a reply to message #633732] Tue, 19 October 2010 07:43 Go to previous messageGo to next message
Dmitry Sklyut is currently offline Dmitry SklyutFriend
Messages: 276
Registered: January 2010
Senior Member
It looks like "auto-export" publishes a bit too much Smile

With option 2 - you are only publishing with:
String serviceName = javax.persistence.EntityManagerFactory.class.getName() ;


Change auto-export to
<osgi:service ref = "entityManagerFactory" interface="javax.persistence.EntityManagerFactory" context-class-loader="service-provider" />


Spring DM will check the type of the class it needs to handle TCCL for and if it is a "class" it will try to use CGLIB. In case of Interface - it will use JDK Proxy.
Re: How to inject EntityManager in each bundle? [message #633758 is a reply to message #633735] Tue, 19 October 2010 09:55 Go to previous messageGo to next message
guofeng zhang is currently offline guofeng zhangFriend
Messages: 49
Registered: July 2009
Member
Using:
<osgi:service ref = "entityManagerFactory" interface="javax.persistence.EntityManagerFactory" context-class-loader="service-provider" />

It still does not work.

Caused by: java.lang.NoClassDefFoundError: Could not initialize class $Proxy243
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Nativ e Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Native ConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(De legatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:5 13)
at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:588)
at org.springframework.orm.jpa.ExtendedEntityManagerCreator.cre ateProxy(ExtendedEntityManagerCreator.java:264)
at org.springframework.orm.jpa.ExtendedEntityManagerCreator.cre ateProxy(ExtendedEntityManagerCreator.java:229)
at org.springframework.orm.jpa.ExtendedEntityManagerCreator.cre ateApplicationManagedEntityManager(ExtendedEntityManagerCrea tor.java:110)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean .invokeProxyMethod(AbstractEntityManagerFactoryBean.java:426 )
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean $ManagedEntityManagerFactoryInvocationHandler.invoke(Abstrac tEntityManagerFactoryBean.java:485)
at $Proxy235.createEntityManager(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsin gReflection(AopUtils.java:309)
at org.springframework.aop.framework.ReflectiveMethodInvocation .invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation .proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.osgi.service.util.internal.aop.ServiceTC CLInterceptor.invokeUnprivileged(ServiceTCCLInterceptor.java :56)
at org.springframework.osgi.service.util.internal.aop.ServiceTC CLInterceptor.invoke(ServiceTCCLInterceptor.java:39)
at org.springframework.aop.framework.ReflectiveMethodInvocation .proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke( JdkDynamicAopProxy.java:202)
at $Proxy240.createEntityManager(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsin gReflection(AopUtils.java:309)
at org.springframework.osgi.service.importer.support.internal.a op.ServiceInvoker.doInvoke(ServiceInvoker.java:58)
at org.springframework.osgi.service.importer.support.internal.a op.ServiceInvoker.invoke(ServiceInvoker.java:62)
at org.springframework.aop.framework.ReflectiveMethodInvocation .proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.support.DelegatingIntroductionInterc eptor.doProceed(DelegatingIntroductionInterceptor.java:131)
at org.springframework.aop.support.DelegatingIntroductionInterc eptor.invoke(DelegatingIntroductionInterceptor.java:119)
at org.springframework.aop.framework.ReflectiveMethodInvocation .proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.osgi.service.importer.support.LocalBundl eContextAdvice.invoke(LocalBundleContextAdvice.java:59)
at org.springframework.aop.framework.ReflectiveMethodInvocation .proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.support.DelegatingIntroductionInterc eptor.doProceed(DelegatingIntroductionInterceptor.java:131)
at org.springframework.aop.support.DelegatingIntroductionInterc eptor.invoke(DelegatingIntroductionInterceptor.java:119)
at org.springframework.aop.framework.ReflectiveMethodInvocation .proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke( JdkDynamicAopProxy.java:202)
at $Proxy251.createEntityManager(Unknown Source)
at org.springframework.orm.jpa.EntityManagerFactoryUtils.doGetT ransactionalEntityManager(EntityManagerFactoryUtils.java:195 )
at org.springframework.orm.jpa.SharedEntityManagerCreator$Share dEntityManagerInvocationHandler.invoke(SharedEntityManagerCr eator.java:211)
at $Proxy180.persist(Unknown Source)
at org.planner.service.member.management.impl.HelloWorldDAO.sav e(HelloWorldDAO.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsin gReflection(AopUtils.java:309)
at org.springframework.aop.framework.ReflectiveMethodInvocation .invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation .proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInter ceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation .proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke( JdkDynamicAopProxy.java:202)
at $Proxy252.save(Unknown Source)
at org.planner.service.member.management.impltest.Activator.sta rt(Activator.java:41)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1 .run(BundleContextImpl.java:783)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.s tartActivator(BundleContextImpl.java:774)
... 35 common frames omitted



Re: How to inject EntityManager in each bundle? [message #634535 is a reply to message #633047] Fri, 22 October 2010 07:13 Go to previous messageGo to next message
guofeng zhang is currently offline guofeng zhangFriend
Messages: 49
Registered: July 2009
Member
It worked without "context-class-loader" defined.
<osgi:service ref = "entityManagerFactory" interface="javax.persistence.EntityManagerFactory" />

Is it that because I use EcliseLink, not Hiberante?
Re: How to inject EntityManager in each bundle? [message #635210 is a reply to message #634535] Tue, 26 October 2010 01:10 Go to previous messageGo to next message
Dmitry Sklyut is currently offline Dmitry SklyutFriend
Messages: 276
Registered: January 2010
Senior Member
Very possibly so. I have spent most of my time trying to shoehorn hibernate. We are also using "native" hibernate not JPA.

EclipseLink should have better OSGi support being developed under Eclipse umbrella.
Re: How to inject EntityManager in each bundle? [message #636072 is a reply to message #635210] Fri, 29 October 2010 08:57 Go to previous message
guofeng zhang is currently offline guofeng zhangFriend
Messages: 49
Registered: July 2009
Member
This is a class loader issue, and it is might not be related to EclipseLink or Hibernate.

I re-tested (using context-class-loader attribute):
<osgi:service ref = "entityManagerFactory" context-class-loader="service-provider" interface="javax.persistence.EntityManagerFactory" />

It works now.

As my work going on, I re-factor my bundles and the EM is injected in another bundle. Maybe this bundle's import makes it works.

But I still cannot know which class is not imported and cause NoClassDefFoundError.

Thanks for your help.
Previous Topic:dm Server Tools manifest problem
Next Topic:AnnotationFormatError: what does it means and how to solve it?
Goto Forum:
  


Current Time: Mon Nov 24 02:51:46 GMT 2014

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

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