[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.rt.eclipselink] Re: Equinox weaving configuration - Clasloading issue
|
Hi Thomas,
There are two problems with your example #2 where you spread the code
and config files across two bundles. The first, and most critical is that
you don't provide the required classloader as a property when you create
your EntityManagerFactory. You have:
EntityManagerFactory emf = Persistence
.createEntityManagerFactory("hello.jpa");
But the byte code weaving example says you should have something like:
Map<String,Object> properties = new HashMap<String, Object>();
properties.put(PersistenceUnitProperties.CLASSLOADER,
this.getClass().getClassLoader());
emf = Persistence.createEntityManagerFactory("comics", properties);
In the weaving example, the classloader that is passed is the one for the
Entities. In the example, since all the code is on the same bundle the
classloader for the Activator is passed.
The second issue, which is related to the first one, is packaging.
EclipseLink's OSGi support for JPA supports lots of different packaging
options but the use of weaving does limit those options. To perform
weaving EclipseLink uses a temporary classloader. This temp loader
examines the Entities (identified through the persistence.xml) to
determine how to weave the classes and is then discarded. Later, when you
load the classes, the weaving is performed. EclipseLink currently builds
a temp loader based on the classloader that is passed as a property to
createEntityManagerFactory.
In your code, you've separated the Entities and persistence.xml and have
no way to get a handle to the actual classloader of your Entities. For
now, if you want to use weaving, I would recommend putting the Entities,
persistence.xml, any orm.xml files, and the EntityManagerFactory creation
code in the same bundle so all classes and config files are loadable by
the same classloader.
This situation will be improving in future releases of EclipseLink. We
have a few initiatives on-going. We're investigating a non-temploader
approach to weaving, it may be possibile to leverage the work of the
Equinox Aspects team to implement EclipseLink's weaving in OSGi, and the
OSGi JPA RFC 143 will introduce standards around how JPA should work in
OSGi. So there is quite a lot going on in this area but it is still in
process.
Until then, I'm afraid if you want to use dynamic weaving you'll have to
live with the current restrictions. Your other alternative is to use
static weaving.
Hope this helps,
--Shaun