Is there any way in hibernate to disable 2nd level caching for particular Property (by provide some ignore caching property) in .hbm file?
For Example,I have TextObject.hbm.xml file as following
<hibernate-mapping default-cascade="save-update" auto-import="false">
<class name="com.nish.TextObject" table="TEXT_TABLE" schema="SFMFG">
<cache usage="read-write" />
<id name="objectId" type="string">
<column name="OBJECT_ID" length="40" />
<generator class="assigned" />
</id>
<property name="text" type="clob">
<column name="TEXT">
<comment>Text</comment>
</column>
</property>
<property name="plainText" type="string">
<column name="PLAIN_TEXT">
<comment>Plain text</comment>
</column>
</property>
</class>
</hibernate-mapping>
By Using <cache usage="read-write" /> I have enabled class level caching .
Requirement: : What i want
- If I shoot hibernate query to get
TextObject.textproperty then it should not be cached. - But if I shoot hibernate query to get
TextObject.plainTextthen it should be cached. - In Summary, For few properties which i have configured in .hbm file, caching should be disabled and for few properties which i have not configured, caching should be enabled.
Reason for the question:
- Hibernate is not allowed to cache clob values, so while fetching property with
type = 'clob'caching should must be be disabled but for other cachable properties cashing should be enabled.
Note :
- Yes, I can Disable Class level caching by removing
<cache usage="read-write" />but that's the last case of remove caching for whole entity class.