Transaction Management with StatelessSession in Hibernation

I have a problem using StatelessSession

and ScrollableResults

in spring application with hibernate. I have several DAOs, mostly using a shared session object, but for one purpose I need to iterate over the whole table. I found out that it is efficient to do this ScrollableResults

to iterate over objects and StatelessSession

not store any results attached in memory. However, I need to do this iteration outside of the DAO because the information from the DB is used to access the external API. So I created methods to create and closeStatelessSession

from the DAO side. I wonder how in this case I should manage the transactions? It seems that transactions are not needed at all (data is only read), but when checking the code, I was told that a transaction can be created automatically and never closed by spring Hibernate Transaction Manager. So should it be manually overloaded or would it be a useless precaution?

+3


source to share





All Articles