I am using <union-subclass> construct in one of my mapping files. AttributeValue is the superclass and StringAttributeValue and IntegerAttributeValue are union-subclasses. Enabling cache for AttributeValue does not enable cache for the subclasses. Is this an expected behavior ?
Hibernate version: Hibernate3
Mapping documents:
Code:
<class name="package.AttributeValue">
<cache usage="read-write"/>
<id
name="id"
column="ID"
unsaved-value="0">
<generator class="increment"/>
</id>
<union-subclass name="package.StringAttributeValue" table="STRINGATTRIBUTE">
<property name="value">
<column name="VALUE" not-null="true" unique="true" index="STRATT_VAL_IDX"/>
</property>
</union-subclass>
<union-subclass name="package.IntegerAttributeValue" table="INTEGERATTRIBUTE">
<property name="value">
<column name="VALUE" not-null="true" unique="true" index="INTATT_VAL_IDX"/>
</property>
</union-subclass>
</class>
Printing entries in "names" array in the following code
Code:
String[] names = HibernateUtil.getSessionFactory().getStatistics().getSecondLevelCacheRegionNames();
does not list StringAttributeValue and IntegerAttributeValue.
A typical HQL in my application would look like
Code:
"from StringAttributeValue sav where sav.value=:nameString"
I want this query to look in the cache before it goes to the db. But it is not happening. It always checks in the db and because of that I get duplicate StringAttributeValue/IntegerAttributeValue objects thus violating unique constraint on value columns.
Any thoughts ?