Hibernate version:
Hibernate 2.1.4 with ehcache 0.9
Mapping documents:
Code:
<class name="State" table="AMFLIBC.MBDLREP" lazy="false" mutable="false">
<cache usage="read-only"/>
<composite-id>
<key-property name="countryCode" type="string" column="DLCOCD" access="field"/>
<key-property name="code" type="string" column="DLBYCD" access="field"/>
</composite-id>
<property
name="name"
column="DLA7TX"
type="string"
access="field"
/>
</class>
Code between sessionFactory.openSession() and session.close():Code:
Session session=sessionFactory.createSession();
State key = new State();
key.countryCode=countryCode;
key.code=stateCode;
State s=(State)session.get(State.class,key);
Name and version of the database you are using:DB2 8.1
Cache configurationCode:
<cache name="com.test.State"
maxElementsInMemory="10000"
eternal="true"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
overflowToDisk="false"
/>
Hello,
We are trying to obtain an object that is saved on the cache, but we need hibernate to return allways the same reference. The object is inmutable and it's cache property is set to "Read Only". However, although we are sure the object is saved in secondary cache, and the cache returns the same reference everytime, Hibernate seen to clone it and returns a different copy of the object.
Is there a way to change this behavior and make hibernate to return the same object in cache (without clonning it)?
Thanks.