-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Description
Following up on basic JPA 4.0 runtime compatibility in #35705, we can add transactional support for EntityAgent management, similar to the existing support for Hibernate's StatelessSession in #7184.
The SmartFactoryBean#getObject(Class) mechanism can be used for dependency injection, along the lines of LocalSessionFactoryBean but following @PersistenceContext-style semantics for the EntityAgent proxy: delegating to a transactional EntityAgent if a transaction is active, performing a non-transactional operation otherwise.
The following additions are to be expected:
SharedEntityAgentCreatornext toSharedEntityManagerCreator(possibly sharing a commonInvocationHandlerimplementation, in particular a commonDeferredQueryInvocationHandler). While this will require building against the JPA 4.0 API, that class is standalone and does not break JPA 3.2 compatibility.AbstractEntityManagerFactoryBean#getObject(Class)supporting a sharedEntityAgentinstance next to its sharedEntityManager. This will require reflective loading of theEntityAgenttype without a hard reference to it, plus conditional initialization of an untypedsharedEntityAgentfield viaSharedEntityAgentCreatorthat can then be returned fromgetObject(Class)if the requested type is assignable to the reflectively loadedEntityAgentClass.- Optional
@PersistenceAgentinjection support inPersistenceAnnotationBeanPostProcessor, along the lines of our existing@PersistenceContextsupport. - Potential additions to our
JpaDialectSPI, covering the creation ofEntityAgentinstances that take the transaction context from an existingEntityManagerorConnectioninstance (similar to how we derive HibernateStatelessSessioninstances). This might pose a challenge with conditional JPA 4.0 support since it exposes theEntityAgenttype in hardJpaDialectmethod signatures.
Build-wise, we will need EclipseLink 6.0 and Hibernate 8.0 pre-release versions and just aim for runtime compatibility with JPA 3.2 providers through integration testing. This is the strongest constraint for actual inclusion. Depending on provider availability and JPA 3.2 versus 4.0 compatibility compromises, we might only be able to do #35705 in Spring Framework 7.1 - through building against JPA 3.2 and providing runtime compatibility with JPA 4.0 - and then do EntityAgent support in a later release.