Transaction-Control-Service and Class-Identities after redeploy

11 views
Skip to first unread message

Marc Schlegel

unread,
Mar 20, 2017, 5:22:29 AM3/20/17
to bndtools-users
Hello everyone.

I`ve got a question about the upcoming transaction-control-service for JPA regarding class-identities. I stumbled upon this statement on Stackoverflow

Classes are not equal after a hot load. Say, for instance you have a tangosol cache layer on hibernate. It is filled with Fork.class, outside of the OSGi scope. You hotload a new jar, and Fork has not changed. Class[Fork] != Class[Fork]. It also appears during serialization, for the same underlying causes.

It occured to me that once you redeploy a bundle containing entity-classes, you get a new classloader instance for the contained entites. How is this solved if classes are still in some JPA-provider cache? Do we make sure to invalidate the caches?

Thanks 

Timothy Ward

unread,
Mar 20, 2017, 5:47:01 AM3/20/17
to bndtool...@googlegroups.com
It depends a little how you use the JPA support in Transaction Control. If you use it in a non-dynamic way then there’s not much we can do, but the easiest (and recommended) ways to use Transaction control handle this by relying on the JPA service to do the right thing. 

When using the JPA service the bundle containing the entity classes also contains the persistence.xml and is called the “persistence bundle”. When this bundle is started the JPA service will create an EMF for it and register it in the service registry. When this bundle is stopped the JPA service will unregister the EMF. When the bundle is unresolved/uninstalled the JPA service will close/discard the EMF.

In this model - if the cache is defined in the persistence unit, then it will be automatically recreated when the EMF is recreated and there is no risk of invalid entries. If the cache is defined outside the persistence unit then it must be more carefully managed by the person providing it, however this should happen automatically if they are listening for the EMF services being created.

As for Transaction Control, all of this fits with the normal service lifecycle. Services should be discarded by consumers when the services are unregistered, which includes the Transaction Control Resource Providers as well as the Transaction Control service itself.

I hope this helps.

Tim


--
You received this message because you are subscribed to the Google Groups "bndtools-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bndtools-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marc Schlegel

unread,
Mar 20, 2017, 5:57:41 AM3/20/17
to bndtools-users
Thanks for the clarification Tim
Reply all
Reply to author
Forward
0 new messages