Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] OSGI Manifest

Tom,

Well, my issue stems from the use of createEntityManagerFactory which
basically forces settings to be in persistence.xml

Based on the signatures createEntityManagerFactory matches the
following spring entitymanager factory.

http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/orm/jpa/LocalEntityManagerFactoryBean.html
http://fisheye1.atlassian.com/browse/springframework/spring/tiger/src/org/springframework/orm/jpa/LocalEntityManagerFactoryBean.java?r=1.15

Configuration settings are usually read from a
META-INF/persistence.xml  config file, residing in the class path,
according to the JPA standalone bootstrap contract.

However createContainerEntityManagerFactory  matches the following
spring entitymanager factory

http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.html
http://fisheye1.atlassian.com/browse/springframework/spring/tiger/src/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java?r=1.19

As with LocalEntityManagerFactoryBean, configuration settings are
usually read in from a META-INF/persistence.xml config file, residing
in the class path, according to the general JPA configuration
contract. However, this FactoryBean is more flexible in that you can
override the location of the persistence.xml file, specify the JDBC
DataSources to link to, etc. Furthermore, it allows for pluggable
class instrumentation through Spring's LoadTimeWeaver abstraction,
instead of being tied to a special VM agent specified on JVM startup.

Now, I have looked at the example osgi eclipselink code, I just really
dislike the fact there's no way to pass in say a datasource.
And that it must be defined in the persistence.xml.  The way (as I
understand) to do that would be through the
createContainerEntityManagerFactory   method.  Which isn't supported.

I guess as a workaround I'll need to create my own version to populate
the datasource and other config into the properties that I don't want
to put in the persistence.xml directly.  [I was already instantiating
a datasource in another osgi bundle etc etc]

No major deal no flow I guess.  Thanks for your help :)

Cheers,
Eric G.

On Wed, Oct 15, 2008 at 4:27 PM, Tom Ware <tom.ware@xxxxxxxxxx> wrote:
> Hi Eric,
>
>  I am not sure what the implications are for Spring, but here is the
> difference between createEntityManagerFactory and
> createContainerEntityManagerFactory.
>
>  createContainerEntityManagerFactory is provided by a JPA provider as a hook
> for a JavaEE container.  A container calls this method and provides an
> instance of PersistenceUnitInfo.  persistenceUnitInfo contains a bunch of
> information that has been initialized by the container and also some special
> hooks that allow us to perform some "class loader magic" and do things like
> weaving.  At the moment, Spring provides a wrapper that emulates a Java EE
> container for the purpose of JPA.  I must admit to being a little ignorant
> about whether there is a way to use it in OSGI, but doing so would require
> specific support from Spring.
>
>  createEntityManagerFactory is for use of JPA outside of a JavaEE container.
> In createEntityManagerFactory, the JPA provider does all its own
> initialization.  This allows it to be used in more environments, but
> disallows the "class loader magic" mentioned above and changes the
> assumptions the provider can make about how things are deployed.
>
> -Tom
>
> Eric Gulatee wrote:
>>
>> Going through the eclipselink code.
>>
>> Since I want to use spring, osgi and eclipselink.
>>
>> -  I was hoping to declare my datasource in the spring configuration file.
>> -  Use one of the entitymanagerfactory wrappers from spring.
>>
>> However,
>> LocalContainerEntityManagerFactoryBean
>> calls
>> PersistenceProvider.createContainerEntityManagerFactory
>> which isn't supported in an OSGI container...
>>
>> So my other option is using the presistenceprovider and calling
>> .createEntityManagerFactory, however, AFAIK, I would need to flatten
>> my DS as properties to be able to pass them in.  (I think that's
>> possible)
>>
>>
>> So...  would it be possible to support
>> createContainerEntityManagerFactory in an osgi container?  I don't
>> really understand the implications or why it's not currently supported
>> in osgi.
>>
>> Cheers,
>> Eric G.
>>
>>
>> On Wed, Oct 15, 2008 at 3:51 PM, Eric Gulatee <eric.gulatee@xxxxxxxxx>
>> wrote:
>>>
>>> Tom,
>>>
>>> I edited the manifest for org.eclipse.persistence.jpa-1.1-M2.jar
>>> I added an import for javax.sql.
>>> My error [see below] went away :)
>>>
>>> I looked at the code, still not sure why that line in
>>> PersistenceUnitProcessor has anything to do with javax.sql.Datasource.  I
>>> must be missing something.  Anyhow.
>>>
>>> [2008-10-15 15:40:06.860] server-dm-16             <SPDE0020E>
>>> Application context creation failure for bundle 'com.da.da-dao-eclipselink'.
>>> org.springframework.beans.factory.BeanCreationException: Error creating
>>> bean with name 'entityManagerFactoryPrivate' defined in URL
>>> [bundleentry://87/
>>> META-INF/spring/applicationContext-db-eclipselink.xml]: Instantiation of
>>> bean failed; nested exception is
>>> org.springframework.beans.factory.BeanDefini
>>> tionStoreException: Factory method [public
>>> javax.persistence.EntityManagerFactory
>>> org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerF
>>> actory(java.lang.String,java.util.Map)] threw exception; nested exception
>>> is java.lang.NoClassDefFoundError: javax/sql/DataSource
>>>        at
>>> org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:444)
>>>        at
>>> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFacto
>>> ry.java:903)
>>>        at
>>> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:817
>>> )
>>>        at
>>> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)
>>>        at
>>> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
>>>        at java.security.AccessController.doPrivileged(Native Method)
>>>        at
>>> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
>>>        at
>>> org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
>>>        at
>>> org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
>>>        at
>>> org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
>>>        at
>>> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
>>>        at
>>> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
>>>        at
>>> org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
>>>        at
>>> org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
>>>        at
>>> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplication
>>> Context.java:276)
>>>        at
>>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(Dependen
>>> cyWaiterApplicationContextExecutor.java:145)
>>>        at
>>> com.springsource.server.kernel.dm.ContextPropagatingTaskExecutor$2.run(ContextPropagatingTaskExecutor.java:82)
>>>        at
>>> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
>>>        at
>>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
>>>        at java.lang.Thread.run(Thread.java:619)
>>> Caused by:
>>> org.springframework.beans.factory.BeanDefinitionStoreException: Factory
>>> method [public javax.persistence.EntityManagerFactory org.eclipse.p
>>>
>>> ersistence.jpa.PersistenceProvider.createEntityManagerFactory(java.lang.String,java.util.Map)]
>>> threw exception; nested exception is java.lang.NoClassD
>>> efFoundError: javax/sql/DataSource
>>>        at
>>> org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:127)
>>>        at
>>> org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:435)
>>>        ... 19 more
>>> Caused by: java.lang.NoClassDefFoundError: javax/sql/DataSource
>>>        at
>>> org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processPersistenceXML(PersistenceUnitProcessor.java:361)
>>>        at
>>> org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processPersistenceArchive(PersistenceUnitProcessor.java:314)
>>>        at
>>> org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.getPersistenceUnits(PersistenceUnitProcessor.java:237)
>>>        at
>>> org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.initPersistenceUnits(JPAInitializer.java:146)
>>>        at
>>> org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.initialize(JPAInitializer.java:135)
>>>        at
>>> org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:104)
>>>        at
>>> org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:64)
>>>        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.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:115)
>>>        ... 20 more
>>>
>>>
>>>
>>> On Wed, Oct 15, 2008 at 11:33 AM, Eric Gulatee <eric.gulatee@xxxxxxxxx>
>>> wrote:
>>>>
>>>> Tom,
>>>>
>>>> -  SpringDM which uses equinox under the covers.
>>>> -  Java 1.6 build 105 from SUN.
>>>>
>>>> Well, correct me if I'm wrong (I may very well be, I'm green/wet behind
>>>> the ears on OSGI), wouldn't the eclipselink jpa 1.1 bundle still need to
>>>> import the javax.sql package even if it's part of the JDK?
>>>> [I get failures when building my own app using mvn-bnd-plugin and
>>>> deploying if javax.sql wasn't import since I'm using a datasource]
>>>>
>>>> Cheers,
>>>> Eric G.
>>>>
>>>> On Wed, Oct 15, 2008 at 9:33 AM, Tom Ware <tom.ware@xxxxxxxxxx> wrote:
>>>>>
>>>>> Hi Eric,
>>>>>
>>>>>  What JVM are you using?  What OSGI framework are you using?
>>>>>
>>>>>  Our testing has mainly been on Sun JDK 1.5 and 1.6 VMs using Equinox.
>>>>>  In that environment, we get the DataSource class from the VM itself.
>>>>>
>>>>> -Tom
>>>>>
>>>>> Eric Gulatee wrote:
>>>>>>
>>>>>> Defect opened.
>>>>>>
>>>>>> Thanks for the prompt response.  And for correcting the verbiage.
>>>>>>
>>>>>> I'm following the POC as a baseline for eclipselink + osgi, and I'm
>>>>>> getting the following error when I create my own activator.  (I'm trying
>>>>>> with eclipselink 1.1-M2)
>>>>>>
>>>>>>
>>>>>> Caused by: java.lang.NoClassDefFoundError: javax/sql/DataSource
>>>>>>   at
>>>>>> org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processPersistenceXML(PersistenceUnitProcessor.java:361)
>>>>>>   at
>>>>>> org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processPersistenceArchive(PersistenceUnitProcessor.java:314)
>>>>>>   at
>>>>>> org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.getPersistenceUnits(PersistenceUnitProcessor.java:237)
>>>>>>   at
>>>>>> org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.initPersistenceUnits(JPAInitializer.java:146)
>>>>>>   at
>>>>>> org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.initialize(JPAInitializer.java:135)
>>>>>>
>>>>>> I don't see the import for javax.sql in the eclipselink jpa osgi
>>>>>> 1.1-M2 bundle. I'm not sure if that's intentional or not.  Or If I've done
>>>>>> something wrong :)
>>>>>>
>>>>>> Cheers,
>>>>>> Eric G.
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Tue, Oct 14, 2008 at 10:18 AM, Tom Ware <tom.ware@xxxxxxxxxx
>>>>>> <mailto:tom.ware@xxxxxxxxxx>> wrote:
>>>>>>
>>>>>>   Hi Eric,
>>>>>>
>>>>>>    You are correct.  At the moment, we are not including version
>>>>>>   numbers of the packages we export.  It would be a good idea to enter
>>>>>>   a bugzilla issue to have this resolved.
>>>>>>
>>>>>>    I believe the reason we do not see a lot of traffic on the mailing
>>>>>>   lists about this issue is that if you import the EclipseLink bundles
>>>>>>   as bundles (rather than as packages) things should work.  That may
>>>>>>   provide a workaround for you.
>>>>>>
>>>>>>   -Tom
>>>>>>
>>>>>>   Eric Gulatee wrote:
>>>>>>
>>>>>>       All,
>>>>>>
>>>>>>       I'm currently having trouble deploying the osgi bundles with
>>>>>>       spring on the spring dm server platform.
>>>>>>       It seems to be due to the osgi manifests not containing version
>>>>>>       information. It would seem spring has an optional import on
>>>>>>       versions 1 through 2.
>>>>>>       And since there isn't version info in the 1.1-M2 manifests, it's
>>>>>>       failing to be imported.  [What I've been told]
>>>>>>
>>>>>>       For anyone interested, here's the thread on springsource's
>>>>>> forums.
>>>>>>       http://forum.springframework.org/showthread.php?t=61456
>>>>>>
>>>>>>       Cheers,
>>>>>>       Eric Gulatee.
>>>>>>
>>>>>>
>>>>>>
>>>>>> ------------------------------------------------------------------------
>>>>>>
>>>>>>       _______________________________________________
>>>>>>       eclipselink-users mailing list
>>>>>>       eclipselink-users@xxxxxxxxxxx
>>>>>> <mailto:eclipselink-users@xxxxxxxxxxx>
>>>>>>       https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>>>>>>
>>>>>>   _______________________________________________
>>>>>>   eclipselink-users mailing list
>>>>>>   eclipselink-users@xxxxxxxxxxx <mailto:eclipselink-users@xxxxxxxxxxx>
>>>>>>   https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> ------------------------------------------------------------------------
>>>>>>
>>>>>> _______________________________________________
>>>>>> eclipselink-users mailing list
>>>>>> eclipselink-users@xxxxxxxxxxx
>>>>>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>>>>>
>>>>> _______________________________________________
>>>>> eclipselink-users mailing list
>>>>> eclipselink-users@xxxxxxxxxxx
>>>>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>>
>> _______________________________________________
>> eclipselink-users mailing list
>> eclipselink-users@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>


Back to the top