[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 14:21:36 EDT 2018


Sorry, I hit send too soon, response inline below...

On Tue, Jun 5, 2018 at 1:06 PM, Sanne Grinovero <sanne at hibernate.org> wrote:

> 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.
>

For WildFly, the checking would be important when there are multiple
persistence units that include the same entity class(es), to ensure that
only one thread does the transformation, however, the Hibernate
org.hibernate.engine.spi.Managed marker interface may provide enough
protection.


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

IMO, That would be a doubly bad practice, multiple persistence units
mapping the same entity class with different persistence providers used for
each persistence unit but your right, only the JPA container could prevent
that.


>
> > 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).
>
> +1
>

I don't intend to make any WF code changes for this now, as I think the ORM
Managed marker interface is enough (IMO).

Thanks for the feedback!

Scott


> >
> > 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