-
Feature Request
-
Resolution: Unresolved
-
Major
-
None
-
None
-
None
-
---
-
---
Allow injection of a container managed org.hibernate.StatelessSession for a given persistence unit.
I originally conceived of this as an Enhancement to a bug fix to provide a better contract for Hibernate Data Repositories (see the original issue description below). But after a proper night's sleep it's obvious this would be a generally useful capability and is thus a Feature Request.
Much of the "container managed org.hibernate.StatelessSession for a given persistence unit" is implemented in WFLY-21267, but would need much more testing than was practical for WFLY-21267, where the StatelessSession is an internal detail of a generated class, and not amenable to testing beyond whether the repository properly does persistence operations.
The injection model would be new.
Following is the original description of this issue:
See the WFLY-21267 for a description of what the underlying problem being solved is.
My proposed short term solution to that problem involved using a CDI Extension to analyze CDI injection targets to identify types that are @Repository interface implementations generated by the current (ORM 6.6.x and 7.1.x) Hibernate Data Repositories annotation processors. When found the extension replaces the value of the internal 'session' field with one that holds a StatelessSession implementation that meets the requirements.
This is clearly a workaround, not a long term fix. This issue tracks the long term fix.
The long term fix will involve coordination with the Hibernate team where WF provides a mechanism that a repository impl can use to get a properly managed StatelessSession, and then Hibernate Data Repositories generates code that uses that mechanism.
A mechanism Scott Marlow has discussed with Gavin King could look like:
@PersistenceUnit StatelessSession
This approach cleanly maps to the idea of 'injection of a container managed org.hibernate.StatelessSession for a given persistence unit'.
Perhaps in the future, if Jakarta Persistence standardizes something like StatelessSession it could be:
@PersistenceUnit EntityAgent
Other things to discuss include the expected semantics for closing the StatelessSession. See https://github.com/wildfly/wildfly/pull/19469#discussion_r2614556594 for some discussion related to that.
The solution will also need to account for the different variant of Hibernate Data Repositories that a given WildFly release needs to support. The existing workaround may need to be supported until no WF variants support the Hibernate Data Repositories releases that generate repository impls that require it.
- blocks
-
WFLY-21080 Promote Jakarta Data to 'community' stability
-
- Open
-
- is triggered by
-
WFLY-21267 Jakarta Data repositories improperly share Hibernate StatelessSession instances
-
- Resolved
-