spring-data-jpa icon indicating copy to clipboard operation
spring-data-jpa copied to clipboard

Consider a StatelessSession variant of the SimpleJpaRepository and AOT support

Open mdeinum opened this issue 3 months ago • 2 comments

At the moment the SimpleJpaRepository and generated AOT repositories all use the default EntityManager factory. As a user of Spring Data JPA I would like to have the option to be able to switch to the Hibernate StatelessSession instead of the default stateful EntityManager.

At the moment the only option to do so is to write everything yourself (or only for selected usecases).

It would be nice if there was an option (globally or per method) to indicate that this should use a StatelessSession or regular EntityManager. I'm aware that this would, probably, be a Hibernate only implementation as I"m not aware of existing/similair support in other JPA frameworks.

mdeinum avatar Oct 14 '25 09:10 mdeinum

StatelessSession is currently a Hibernate-only concept. Chances stand well that the stateless-session concept will be included in the JPA 4.0 spec giving us an opportunity to explore a stateless repository implementation.

mp911de avatar Oct 21 '25 07:10 mp911de

Zooming out, what benefits do you get from using a stateless session? Hibernate's stateless session is stateful during query execution and once the query returns objects, then objects get detached.

mp911de avatar Nov 26 '25 15:11 mp911de