-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Description
As of Spring Framework 7.0.4 (#35705), we provide early runtime compatibility with JPA 4.0 and Hibernate ORM 8.0.0.Alpha1, effectively covering the JPA 3.2 usage model (plus a few configuration twists) when running against Hibernate 8.0 at runtime.
Following up on that basic support, 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:
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 that can then be returned fromgetObject(Class)if the requested type is assignable to the reflectively loadedEntityAgentClass.JpaVendorAdapter#getEntityAgentInterface()indicating a vendor-specific interface to use for the sharedEntityAgentproxy, suggestingStatelessSessioninHibernateJpaVendorAdapter.- Optional
@PersistenceAgentinjection support inPersistenceAnnotationBeanPostProcessor, along the lines of our existing@PersistenceContextsupport. Note that@PersistenceAgentis not available in the recently released JPA 4.0 M1 yet.
Complete EntityAgent support will require building against JPA 4.0 and might only be sensible to deliver in Spring Framework 8.0, then against a JPA 4.0 baseline (without any need for JPA 3.2 compatibility). That said, early reflective support is entirely possible in the meantime, covering all common use cases such as a shared @Autowired EntityAgent proxy with transactional management.