views:

232

answers:

2
session.open
insertIntoTODB()
getList()
session.close

session.open()
getList();
sesson.close()

1st leve cache is only bounded in session open and close and for 2nd subsequent session open, getList() will get from DB instead of cache?

+2  A: 

Yes. The 1st level cache is for the session only. The second getList() call will go to the database.

EDIT: The second getList() call will go to the database, in the absence of the second level cache, as well noted by mR_fr0g in his answer.

Bruno Rothgiesser
If getList() is a query by something other than the id (or a full table query), both queries will hit the database, but in the first case, Hibernate will return the objects that are already in the session cache, rather than building them from the database result set. A session.get or load will not have to hit the database at all if the object being retrieved is in the session cache.
Brian Deterling
+3  A: 

The first level cache is session scope. The second getList() will go to the database only in the absence of a second level cache. Second level caches are session factory scoped.

mR_fr0g
Actually I never heard the term first level cache in Hibernate. I only knew about the second level. :)
Adeel Ansari