I’m using Spring with Hibernate. I have some queries that don’t actually need a transaction, but I’m using one because it does the session management for me. What is the correct way of doing these non-transactional read queries without doing my own session management?
Share
I think @Transaction(readOnly=true) is the right way to do it. That’s not going to create a new/extra physical transaction, so there shouldn’t be any overhead to using that. It’s going to use the transaction that was already set up for the request. Per the Hibernate docs:
https://community.jboss.org/wiki/SessionsAndTransactions#Transactions