Hi Steve,

I have another question I stumbled over when working on the new aries jpa code.

I had most problems with the load time weaving support. It currently works like this: Were are creating a PersistenceUnitInfo and call PersistenceProvider.createEntityManagerFactory() with it. At the start of aries jpa container we add a OSGi WeavingHook that initially does nothing. When the persistence provider calls addTransformer on the PersistenceUnitInfo. We add this to the WeavingHook. So when after this point classes of the persistence bundle are loaded they are enhanced.

The problem with this approach is that the weaving has to be done very early (Ideally while the persistence enter state resolved). Calling createEntityManagerFactory on the other hand can only be done when the PersistenceProvider and the DataSource are present. So there is a timing problem here. Aries jpa 1.x solves this by calling createEntityManagerFactory early and using a wrapper on the DataSource that blocks as long as it is not ready. This approach is not very OSGi friendly and can lead to death locks. In the new code I currently call createEntityManagerFactory as soon as both PersistenceProvider and DataSource are found by their trackers. In this case the user has to add a service ref on the EntityManagerFactory service created to avoid that his entity classes are loaded too early. This is a very brittle approach of course.

So what I am thinking of is to completely decouple the enhancement from the EntityManagerFactory creation. Instead the user would need to add a requirement to the persistence unit manifest that specifies he wants jpa enhancement by a certain PersistenceProvider. The persistence provider bundle or a supporting bundle like aries jpa could then provide these capabilty and could then use a BundleTracker to synchronously add the WeavingHook once the bundle enters resolved state. Of course this is no standard but I think it would be much more stable than the current approach.

How does hibernate work in this regard? I noticed that hibernate 4.3.x does not seem to call addTransformer. Do you have another approach for load time weaving?

Christian

Am 16.05.2015 um 01:37 schrieb sebersole:
Hi Bram.  Sorry I do not get notified of replies here for some reason, even
though I subscribed to the mailing list as well.

I think this approach is based on older versions of Hibernate.  As we have
said all along OSGi support in Hibernate 4.2 was a first step, but not
really ready for prime time.  In definitely got better in 4.3 which is what
the Karaf integration is based on I believe.  It is better still in 5.0
which is what I am working on atm.

The work in 4.3 was really about removing code in Hibernate that relies on
TCCL and migrating to rely on the idea of a ClassLoaderService which is
based on an idea of services that I had been working on for quite some time.
So in 4.3 very little, if any, Hibernate code uses TCCL calls.  However, we
do certainly have some libs which we know use TCCL.  5.0 addresses the rest
of TCCL issues, including in the main culprit lib..
hibernate-commons-annotations.  Ultimately I want to replace
hibernate-commons-annotations with Jandex and some other stuff, but that was
not going to fit in 5.0.  So what I did instead was to change
hibernate-commons-annotations to accept help in class loading and I hook
into that from Hibernate delegating to our ClassLoaderService.

Sorry for the history lesson :)

Anyway, I would really need convinced that your pull request is the
direction to go for Hibernate 4.3 and 5.0



--
View this message in context: 
http://karaf.922171.n3.nabble.com/Hibernate-OSGi-Integration-tp4040190p4040394.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Reply via email to