[hibernate-dev] What should be the contract for PersistenceUnitInfo#addTransformer with regard to multiple persistence units mapping the same entity class?
smarlow at redhat.com
Tue Jun 5 14:08:35 EDT 2018
Thanks, I think they probably intended that the persistence provider would
use a marker interface like org.hibernate.engine.spi.Managed to ensure that
the enhancement is only done once. Responses to your questions are inline
On Tue, Jun 5, 2018 at 12:19 PM, Luis Barreiro <lbarreiro at redhat.com> wrote:
> 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 ?!
Mostly, I'm trying to understand why the  javadoc requires that classes
are only transformed only once, as I would expect that some persistence
providers could want to register multiple transformers.
> I don't get you last paragraph ... why ORM will be only capable of
> registering one transformer,
If we update the WildFly JPA container JPADelegatingClassFileTransformer
 to only allow the application entity class to be enhanced at most once
(at runtime), ORM would be able to register multiple transformers but the
first ORM transformer that actually enhances the entity class (e.g.
transformer returns non-null return value), would need to terminate the
"for each transformer" loop in .
Since, as you said, ORM is already using a marker interface to know when a
class is already enhanced, it sounds like WildFly doesn't really need to
enforce the  contract (with regard to only transforming the entity class
> and why will you need synchronization ?!
If WildFly JPADelegatingClassFileTransformer  where modified to prevent
more than one transformation of an entity class, that would include
checking across (parallel) persistence unit deployment threads, which could
be done with a Java synchronization lock.
More information about the hibernate-dev