Skip to content

Support for JPA 4.0 EntityAgent #36025

@jhoeller

Description

@jhoeller

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:

  • SharedEntityAgentCreator next to SharedEntityManagerCreator (possibly sharing a common InvocationHandler implementation, in particular a common DeferredQueryInvocationHandler). 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 shared EntityAgent instance next to its shared EntityManager. This will require reflective loading of the EntityAgent type without a hard reference to it, plus conditional initialization of an untyped sharedEntityAgent field via SharedEntityAgentCreator that can then be returned from getObject(Class) if the requested type is assignable to the reflectively loaded EntityAgent Class.
  • Optional @PersistenceAgent injection support in PersistenceAnnotationBeanPostProcessor, along the lines of our existing @PersistenceContext support.
  • Potential additions to our JpaDialect SPI, covering the creation of EntityAgent instances that take the transaction context from an existing EntityManager or Connection instance (similar to how we derive Hibernate StatelessSession instances). This might pose a challenge with conditional JPA 4.0 support since it exposes the EntityAgent type in hard JpaDialect method 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.

Metadata

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)type: enhancementA general enhancement

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions