Classloading issue w/ TempEquinoxEntityLoaderhttps://www.eclipse.org/forums/index.php/mv/msg/156817/494308/#msg_494308
in my test-scenario my entities are woven if I put them all together into one bundle. But that's not what I want it to be in my existing RCP application. So what needs to be done to make this work? I tried a couple of things but they all failed. Here is what my scenario looks like:

Bundle A contains entity E1, the persistence.xml file and it creates an EMF during the bundle's start-method. Entity E1 is successfully woven. Furthermore I got a bundle B which contains entity E2. Bundle A imports the one and only package of B.

My failed attempts were having Bundle B be an ordinary bundle, be a fragment-bundle of A and also be a fragment-bundle of org.eclipse.persistence.jpa (with the latter one class E2 wasn't even tried to be loaded, with the both first approaches I get a ClassNotFoundException when trying to load class E2).

While debugging I realized that the EquinoxInitializer$TempEquinoxEntityLoader is being asked to load my entities (instead of my handed-in classloader which is saved in the realClassLoader variable). That loader makes a call to findLocalClass which in turn ends up in eclipse.osgi's ClasspathManager being unable to load my class E2.

I really hope someone can help me out with this one. Although I want to use the weaving in my RCP app in the long-run, here I am testing just with a small and simple OSGI runtime configuration.

Thx,
Oliver

]]>Oliver Vesper2009-10-30T08:07:47-00:00Re: Classloading issue w/ TempEquinoxEntityLoaderhttps://www.eclipse.org/forums/index.php/mv/msg/156817/494329/#msg_494329
I'll take a look at this but my initial reaction is that all of your Entities need to be in the same bundle so they all are defined in the same classloader--being loadable by the same loader is not sufficient. This should mean that bundle fragments should also work but I can't say I've tried this yet.

As far as RCP is concerned I've had issues with weaving due to the collision of OSGi services and the way RCP apps launch. But I've picked up some tricks at Eclipse Summit Europe I'm going to try out and if they work out I'll update the RCP example to include weaving.

--Shaun

]]>Shaun Smith2009-10-30T10:18:20-00:00Re: Classloading issue w/ TempEquinoxEntityLoaderhttps://www.eclipse.org/forums/index.php/mv/msg/156817/494339/#msg_494339
thanks for investigating on this issue, I'm really curious about your results. I haven't tried building an rcp app where all entities are in the same bundle. But using a simple osgi run configuration and having the entities located in one bundle the weaving is working as expected.

Besides this placing all entity classes into one bundle does not sound like a very modular design approach - what do you think about this?

Thx for your help,
Oliver
]]>Oliver Vesper2009-10-30T10:50:52-00:00Re: Classloading issue w/ TempEquinoxEntityLoaderhttps://www.eclipse.org/forums/index.php/mv/msg/156817/494471/#msg_494471
now I am really surprised: I just tried out Milestone M11
(eclipselink-plugins-2.0.0.v20091026-r5655) and the weaving is working
fine. It works for entities coming from fragments *and* also for entites
coming from completely different bundles. I haven't debugged into it to
see what's going on differently comparing to the 1.2.0 version.

Next thing I'm gonna try out is to move on from my osgi run
configuration to my RCP environment... Or I'll verify that lazy-loading
is working as expected first... I will post my results here, maybe it's
helpful for anybody else, too.

-Oliver

Shaun Smith schrieb:
> Hi Oliver,
>
> I'll take a look at this but my initial reaction is that all of your
> Entities need to be in the same bundle so they all are defined in the
> same classloader--being loadable by the same loader is not sufficient.
> This should mean that bundle fragments should also work but I can't say
> I've tried this yet.
>
> As far as RCP is concerned I've had issues with weaving due to the
> collision of OSGi services and the way RCP apps launch. But I've picked
> up some tricks at Eclipse Summit Europe I'm going to try out and if
> they work out I'll update the RCP example to include weaving.
>
> --Shaun
>
>]]>Oliver Vesper2009-10-30T18:44:16-00:00Re: Classloading issue w/ TempEquinoxEntityLoaderhttps://www.eclipse.org/forums/index.php/mv/msg/156817/494490/#msg_494490
> configuration to my RCP environment...

Shaun, as you already pointed out, getting weaving to work within RCP is
not that easy. The ClassLoadingHook is registered correctly and it opens
its ServiceTracker for IWeaver services without problems. But now I am
stuck getting the EquinoxInitializer loaded. Creating the EMF like this

Persistence.createEntityManagerFactory("foo", properties);

does not cause the mentioned Initializer to be loaded - instead it uses
the OSGIInitializer. So I tried to force using the EquinoxInitializer by
creating the EMF this way:

Please ignore my last posting! For some very very weird reason my RCP
app did not include the org.eclipse.persistence.jpa.equinox fragment.
After adding it, the EquinoxInitializer is being loaded and my entities
are woven. Finally got the weaving working!

-Oliver]]>Oliver Vesper2009-10-30T21:50:23-00:00Re: Classloading issue w/ TempEquinoxEntityLoaderhttps://www.eclipse.org/forums/index.php/mv/msg/156817/495147/#msg_495147
Just to confirm that in pre 2.0 EclipseLink you do need all of your entities in the same bundle as your persistence.xml for weaving to work. However as you have discovered this restriction will be gone in EclipseLink 2.0. This is because we've removed the need for direct access to the classloader of the persistence unit. So with EclipseLink 2.0 you can just create an EntityManagerFactory with the name of the persistence unit and no longer pass a classloader.

I'll be updating the OSGi examples on the wiki for EclipseLink 2.0.

Also, at Eclipse Summit Europe last week I was speaking with Martin Lippert who suggested that the way to enable weaving in an RCP app was to ensure that the org.eclipse.core.runtime bundle is started after the o.e.p.jpa and javax.persistence bundles. The core runtime bundle launches the RCP application and you want to make sure that EclipseLink has setup weaving before the application loads an Entity class. I haven't tried this out yet but thought I'd pass this on to you since you're actively working with RCP.