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

Sanne Grinovero sanne at hibernate.org
Tue Jun 5 13:06:54 EDT 2018

On 5 June 2018 at 14:43, Scott Marlow <smarlow at redhat.com> wrote:
> 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 suspect it's necessary to do this check in the container.

If you do it in the persistence provider, how can you guarantee that
another persistence provider is not keeping track independently?

> 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
> _______________________________________________
> hibernate-dev mailing list
> hibernate-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/hibernate-dev

More information about the hibernate-dev mailing list