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

Luis Barreiro lbarreiro at redhat.com
Tue Jun 5 12:19:15 EDT 2018


Hi Scott,

In the particular case of the hibernate bytecode enhancer, it adds the 
org.hibernate.engine.spi.Managed marker interface to the entity so that 
it only performs the enhancement once. (that implies that you can't have 
the same entity enhanced for different features in the same class loader)

Also, in theory, you could have multiple transformations applied to the 
same entity / PU. So what is it you really want to check ?!

I don't get you last paragraph ... why ORM will be only capable of 
registering one transformer, and why will you need synchronization ?!

Regards,

Luis Barreiro

Middleware Performance Team

<https://red.ht/sig>

On 06/05/2018 02:43 PM, Scott Marlow 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 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