Hello,
It seems that where attribute does not work in the sets in some situations. I am using Hibernate 2.1.4 and the database is Oracle9.
This is a clip of a mapping with two quite similar sets:
Code:
<class name="Instance" table="instances">
<composite-id name="id" class="InstanceId">
<key-property name="familyId" type="string" column="instance_family_id"/>
<key-property name="version" type="integer" column="version"/>
</composite-id>
<set name="primaryComponentRelations" lazy="false" inverse="false" where="is_primary = 1" table="components_instances">
<key>
<column name="instance_family_id"/>
<column name="version"/>
</key>
<one-to-many class="ComponentInstanceRelation"/>
</set>
<set name="alternativeComponentRelations" lazy="false"
inverse="false" where="is_primary = 0" table="components_instances">
<key>
<column name="instance_family_id"/>
<column name="version"/>
</key>
<one-to-many class="ComponentInstanceRelation"/>
</set>
</class>
As you can see there is two sets, with the difference that boolean field is_primary has different value.
Here is the mapping of the ComponentInstanceRelation:
Code:
<class name="ComponentInstanceRelation" lazy="true" table="components_instances">
<composite-id name="id">
<key-property name="caseId" type="string" column="vcase_id"/>
<key-property name="index" type="integer" column="comp_index"/>
<key-property name="instanceFamilyId" type="string" column="instance_family_id"/>
<key-property name="version" column="version" type="integer"/>
</composite-id>
<property name="name" type="string" column="name"/>
<property name="primary" column="is_primary" type="boolean" not-null="true"/>
<property name="componentName" column="component_name"/>
<property name="labelName" not-null="true" column="label_name"/>
<many-to-one name="instance" class="Instance" insert="false" update="false">
<column name="instance_family_id"/>
<column name="version"/>
</many-to-one>
<many-to-one name="component" class="Component" insert="false" update="false">
<column name="vcase_id"/>
<column name="comp_index"/>
</many-to-one>
</class>
ComponentInstanceRelation is just a middle table, but I implemented it as a normal mapping, because it has to do some complicated operations and I could not get them working when it was mapped as composite-element. Such as, when a new version of the Instance is created, relation must be changed to it from the old instance. This means that at database level relation must be deleted and a new must be created with different instance.
The new implementation seems to work, but the problem is that both getPrimaryComponentRelations() and getAlternativeComponentRelations() in the Instance give the same set of ComponentInstanceRelation objects as result. When checked from database there is an instance with 166 primary relations (is_primary=1) and 0 alternative relations(is_primary=0). However when using Hibernate, both sets contain all 166 relations.
So my question is, is there a bug in Hibernate and if not, what am I doing wrong, and if there is a bug, how do I get around it?