When using read/write strategy are the objects(business objects/entity objects) cached in the session factory? In the code below it does not seem to use the cache and hits the DB each time the code tries to load it from a new session. So does that mean that if you use read/write strategy no second level caching is provided?
Note:
1. if i use read-only & nonstrict-read-write the caching seems to work and does not hit the DB on subsequent loads.
2. I went through the documents, forum and was not able to get enough information to understand why it was not caching in read/write strategy.
3. i do not want to cache the query, i want to cache the objects that are already loaded to reduce the db hits.
mapping file :
Code:
<hibernate-mapping>
<class name="uk.co.ReviewImpl" proxy="uk.co.idbs.product.Review" table="pd_reviews">
<cache usage="read-write"/>
<id name="id" column="id" type="string" unsaved-value="null">
<generator class="uuid.hex"/>
</id>
<version name="auditVersion"/>
<property name="reviewer" type="string"/>
<property name="score" type="integer"/>
<property name="comment" type="string" column="cment"/>
<property name="buyAgain" type="yes_no"/>
</class>
</hibernate-mapping>
code:
Code:
sessionFactory = hibernateConfiguration.buildSessionFactory();
Session session = null;
session = sessionFactory.openSession();
Object obj1 = session.load(....)
session.close();
// here i was expecting it to get from cache instead of loading it from DB. But it is loading from DB
session = sessionFactory.openSession();
Object obj2 = session.load(....)
session.close();
I am using net.sf.ehcache.hibernate.Provider