Currently using
Hibernate 4.3.6 Final
NON-JPA ... using hibernate mapping files. No annotations
Question:NaturalID lookup support for Second Level Cache...
It appears (looking at Hibernate L2 Statistics) that this is supported differently in Hibernate 4 vs 3, and presumably more efficiently in Hibernate 4.
However, we have been unable to utilize it.
Mapping is straightforward:
Code:
<class name="com.trivin.bo.CodedValue" discriminator-value="0" mutable="true" dynamic-update="false" table="CODED_VALUES">
<cache usage="read-write" />
<id name="codedValueID" column="VALUE_ID" type="long">
<generator class="native" />
</id>
<discriminator column="TYPE_ID" type="integer" force="false" insert="false" not-null="true" />
<natural-id mutable="false">
<property name="productID" column="PRODUCTID" />
<property name="typeID" type="integer" column="TYPE_ID" />
<property name="code" column="CODE" length="30" />
</natural-id>
<property name="description" column="DESCRIPTION" length="100" />
When interrogating the Hibernate Configuration at runtime, the "naturalIdCacheRegionName" is null. Not sure if that is relevant.
After many calls using Session.byNaturalId(...) we do not see any caching taking place in L2, querying and viewing the cache.
Articles on the net seem to indicate that this is turned on via an Annotation. I do not see any other setting in the Hibernate Mapping file that might correspond to this.
Can somebody confirm that this support is or is not available without annotating? If so, is this still the case in Hibernate 5?
We just do not want to keep chasing down something that may not be supported.
No, we cannot move to annotate our hundreds and hundreds of classes at this point, as it would require much work, testing, etc.
As a side note, we could do the lookup using straight basic criteria lookup with query cache on, we do see caching taking place with this approach. But, we'd like to eliminate query cache, and we are seeing issues with query cache/filter clashes with duplicates generated in L2 cache.
thanks for any input or advice.