Hibernate has two levels of Cache,
- Session cache (First level cache) is default cache and there is no mechanism to disable.
- SessionFactory (second level) level cache : We have to configure this in Hibernate cfg file by setting cache_provider.
I had an requirement to load heavy data from DB, and I used stateless session because of following features.
a. Stateless session does not support session cache and never interact with second level cache. b. Stateless session does not support automatic dirty check. c. Stateless session does not support cascading to associated entities.Syntax to create Stateless session:
StatelessSession statelessSession = sessionFactory.openStatelessSession();