|
In Aries JPA we currently use the OSGi WeavingHook to enhance classes.
In PersistenceUnit.addTransformer(ClassTransformer transformer) we capture the transformer and register it with the JPAWeavingHook impl. Then in JPAWeavingHook we can add the necessary imports into the bundle wiring and call the transformer. This allows to use just the standard bundle classloader and still provide a way to enhance the classes.
Currently this approach is not working perfectly. There are two issues: 1. In some cicumstances the classes are loaded before the transformer is registered. The problem here is that we must create an EntityManagerFactory to get the transformer. This is sometimes too late. 2. We do not have informations which packages are needed from the PersistenceProvider. So we currently add some well known packages blindly
I wonder if a similar approach could be done by hibernate independently from Aries JPA. Hibernate could register a WeavingHook early in the framework startup and do the enhancements when a bundle has hibernate imports or maybe when a certain Manifest header is present. If you are interested in that approach I could create a prototype.
|