[hibernate-dev] What should be the contract for PersistenceUnitInfo#addTransformer with regard to multiple persistence units mapping the same entity class?

Scott Marlow smarlow at redhat.com
Tue Jun 5 09:43:51 EDT 2018


The PersistenceUnitInfo#addTransformer javadoc [1] mentions:

"
Add a transformer supplied by the provider that will be called for every
new class definition or class redefinition that gets loaded by the loader
returned by the getClassLoader()
<https://docs.oracle.com/javaee/7/api/javax/persistence/spi/PersistenceUnitInfo.html#getClassLoader-->
method. The transformer has no effect on the result returned by the
getNewTempClassLoader()
<https://docs.oracle.com/javaee/7/api/javax/persistence/spi/PersistenceUnitInfo.html#getNewTempClassLoader-->
method. Classes are only transformed once within the same classloading
scope, regardless of how many persistence units they may be a part of.
"

Should we have a check somewhere that prevents the same entity class from
being enhanced multiple times?  Should the check be in the JPA container or
in the persistence provider?  Thought I would check here in case anyone
remembers the background of where the check was intended to be exactly.

I assume that WildFly might be the best place to have the check but wanted
to ask here first, because if the JPA container does the checking, that
will mean that ORM will only be able to register one class transformer per
persistence unit.  WildFly will also have to prevent other persistence
units from transforming the same entity class in a different thread (e.g.
since we typically deploy all of the persistence units in parallel, we will
need some synchronization).

Scott

[1]
https://docs.oracle.com/javaee/7/api/javax/persistence/spi/PersistenceUnitInfo.html#addTransformer-javax.persistence.spi.ClassTransformer-

[2] https://github.com/wildfly/wildfly/pull/11297


More information about the hibernate-dev mailing list