The performance hit happens only in a transaction
if I have something like
Code:
begin
session.beginTransaction()
doWorkThatInvolvesQueryAndL2Cache() <-- this is slow
session.commit();
session.close()
end
However if I just have
Code:
begin
doWorkThatInvolvesQueryAndL2Cache() <-- this is FAST
session.close()
end
The core reason that I have transaction around some code that reads data is that some of this code uses .scroll() and scroll.next may fail by closing the result set if it is not in transaction in Hibernate 5 apparently..
Does it make any sense? Am I missing something when doing scroll??