Hibernate 6.6 supports Jakarta Data 1.0 and utilizes Hibernate modelgen tools to generate the Repository
implementation source codes at Java compile time. It is a good match with Spring AOT, no need to transform the Jakarta Data related facilities.
I wrote a post about Spring and Jakarta Data integration before, check https://medium.com/itnext/integrating-jakarta-data-with-spring-0beb5c215f5f
- Scan Jakarta Data
@Repository
as beans - Allow Spring
@Repository
to interoperate the Jakarta Data one - Allow developers to use Jakarta
@Transactional
or Spring@Transactional
(requires support HibernateStatelessSession
)
Comment From: jhoeller
For 7.0, we might reopen #7184 for basic StatelessSession management but won't go as far as providing Jakarta Data support in Spring Framework proper. It looks like this does not fit with the Spring Data project either, so it'll be left to community efforts.
Comment From: leshalv
Thank you for the ongoing discussion and efforts around supporting Hibernate StatelessSession transactions in Spring.
In my project, we heavily rely on Hibernate's StatelessSession for high-performance batch operations, and the lack of proper transaction integration with Spring severely limits our ability to manage transactions declaratively using @Transactional.
Manually managing transactions around StatelessSession is error-prone and breaks the consistency of the Spring transaction model.
This limitation affects not only my team but potentially many users who want to leverage StatelessSession's performance benefits while still using Spring's powerful transaction management features.
Without proper integration, it is difficult to write clean, maintainable, and reliable transactional code using StatelessSession within Spring.
Could the Spring team consider implementing official support for StatelessSession transactions within the Spring transaction abstraction?
It would greatly improve developer experience and allow leveraging both Hibernate's performance optimizations and Spring's declarative transaction management seamlessly.
I would be happy to help test any prototypes or provide feedback during the development process.
Thank you again for your attention and help. @jhoeller
Comment From: jhoeller
@leshalv at the moment, the best you could do is to call SessionFactory#openStatelessSession(connection)
with a connection
obtained from DataSourceUtils.getConnection(dataSource)
- in order to participate in a Spring JdbcTransactionManager
or HibernateTransactionManager
transaction. I suppose that's what you'd like to to happen behind the scenes?
Design-wise, the problem there is the lack of a SessionFactory#getCurrentSession()
style method for StatelessSession
. Hibernate does not have a pattern for managing a transaction-bound StatelessSession
at all, not for JTA and not for Spring-managed transactions either.
For a Spring-specific arrangement, an EntityManager style StatelessSession
proxy could work, to be @Autowired
similar to a shared EntityManager (as per #33414 in Spring Framework 7.0). We could build this into LocalSessionFactoryBean
, automatically enabling such autowiring for both Session
and StatelessSession
. I'll reopen #7184 for that purpose.
Comment From: hantsy
With the StatelessSession
and TX support in Spring, utilizing Hibernate Processor to generate the metadata classes/implementations will work well with Spring.