Hi again,
I can rephrase my question with an example. Any help would be much appreciated.
Consider the example below, with the second level cache in use. The item that is loaded can be obtained from the cache.
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
Item item = (Item) session.load( Item.class, new Long(1234) );
tx.commit();
session.close();
I assume that hibernate gets a database connection when session.beginTransaction() is called and not before?
If I know that the data I want is in the second level cache (it is very infrequently updated reference data), then I do not want a db connection taken from the connection pool for this request.
If I dispense with the transaction code in the above snippet, and the session is only used to read data from the cache, will Hibernate make no contact with the database?
Cheers,
Jim
|