Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Entities in multiple bundles

Hi Bryan,

Bryan Hunt wrote:
Hi Shaun,  thanks for the clarification.  I wrote a hack to start the necessary bundles, and EclipseLink is initializing correctly.
Great!

I'd like to finally start working on an enhancement that allows for the declaration of entities in an extension point, and the ability for a persistence unit to span multiple bundles: https://bugs.eclipse.org/bugs/show_bug.cgi?id=226425

One of the major issues that has to be resolved is the class loader.  I'm guessing that the notion of a single class loader is prevalent throughout the code and adding support for searching multiple class loaders would be prohibitive.  Correct?
It's all about the classloader. :-)  EclipseLink definitely expects a single classloader for a persistence unit but it should be possible for you to build a custom classloader that aggregates a number of classloaders together--essentially a Composite Pattern classloader.  You give EclipseLink your custom loader and it iterates across all the classloaders it contains until it finds the necessary class or resource. 

If you want to use a bundle as a classloader you can wrap it in org.eclipse.persistence.internal.jpa.deployment.osgi.BundleProxyClassLoader.  This class is a "recipe" from the Eclipse wiki: http://wiki.eclipse.org/BundleProxyClassLoader_recipe

I'm thinking the best approach might be to create an extension of PersistenceProvider.  I would use the class loader from the extension bundle as the class loader for the EntityManagerFactory, and use "Eclipse-BuddyPolicy: dependent" so that the entities could be found.  This approach does limit the use to Equinox; however, since it's an extension, it's optional.  I also believe there is interest in solving this class loading problem within OSGi which would then make this extension usable across other implementations of OSGi.
I would encourage you to avoid buddy classloaders if you want to be portable.  Right now EclipseLink has no buddy classloader usage and I don't believe you need them given what you've said.  In fact, I think you can use the technique I suggested above to access classes and resources in extension bundles.  Of course I have abolutely no experience with the Equinox extension framework to back this up.  It just seems to make sense.  If you have, say, 5 bundles that all contain Entities that are part of the same persistence unit you need to ensure that the classloader you provide to EclipseLink can transparently load classes and resources from all 5 bundles.  If you wrapped and added all the extension provider bundles in the composite loader then it should work.

Just some thoughts off the top of my head,

    Shaun

Thoughts?

Bryan

On Nov 4, 2008, at 12:36 PM, Shaun Smith wrote:

Hi Bryan,

   We've coded to generic OSGi and AFAIK there is no generic way to say a bundle should be started.  But I don't see any reason why we couldn't include an Equinox (or other implementation specific) manifest entry though.  Can you file bug for this?  We also need to start the org.eclipse.persistence.jpa bundle.

    In answer to your question: yes you do need to start the bundle yourself.  I set this as part of my launch configuration for OSGi apps using PDE.  It seems to be harder in an RCP app as the PDE launcher doesn't let you set start levels.  You seem to have to put everything into a config.ini file.  I'd love to hear about a simpler way.

    FYI, the resolver behind javax.persistence.Persistence sets up a service tracker that provides an OSGi friendly way of locating persistence providers.  If you don't care if you're directly coupled to EclipseLink then you can go around the JPA SPI interface and directly instantiate org.eclipse.persistence.jpa.osgi.PersistenceProvider and create your EntityManagerFactory.  This is probably the simplest thing to do in an RCP app as it is "service-less".  However you do need to pass in a classloader that can see your persistence.xml, orm.xml, and Entities, e.g.,

            HashMap<String, Object> properties = new HashMap<String, Object>();
            ClassLoader classLoader = this.getClass().getClassLoader();
            properties.put(PersistenceUnitProperties.CLASSLOADER, classLoader);
            new PersistenceProvider().createEntityManagerFactory(puName, properties);

    Shaun

Bryan Hunt wrote:
The Activator in javax.persistence sets the provider resolver to the Activator, but the manifest is set to not automatically activate the bundle.  Is the default provider resolver supposed to be used, or do I manually have to start the bundle?

Bryan
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

--


<oracle_sig_logo.gif>
Shaun Smith | Principal Product Manager, TopLink | +1.905.502.3094
Oracle Fusion Middleware
110 Matheson Boulevard West, Suite 100
Mississauga, Ontario, Canada L5R 3P4
_______________________________________________
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

--


Oracle
Shaun Smith | Principal Product Manager, TopLink | +1.905.502.3094
Oracle Fusion Middleware
110 Matheson Boulevard West, Suite 100
Mississauga, Ontario, Canada L5R 3P4

Back to the top