Hi,
I'm working with a content management system that is limited in the sense that it does not create proper relationships between tables, i.e. foreign key constraints to primary/unique keys.
Each table has a database id, a content id and a status field which describes if a particular row (i.e. the content) has been deleted. Relationships between tables can be built using the content id and by checking the status of a particular row.
I'm currently trying to build a parent/child relationship using the "where" attribute on the class and set elements. I'm also using the "property-ref" attribute to build the key for my set of children.
Can anyone advise me if I am heading along the right track?
Also when i set the fetch="join" i seem to get duplicate elements (equal to the number of children that exist) when i query for all parents. Setting fetch="select" works but causes two selects to be executed. Is there a way to get the join to work as it seems more efficient?
Hibernate mappings are as follows.
Code:
<hibernate-mapping package="test.hibernate" >
<class name="Parent" table="parent" where="status!='DELETED'">
<id name="id" />
<natural-id>
<property name="cid" />
</natural-id>
<property name="name" />
<set name="children" where="status!='DELETED'"
fetch="join" lazy="false" >
<key column="parent_id" property-ref="cid" />
<one-to-many class="Child"/>
</set>
</class>
</hibernate-mapping>
<hibernate-mapping package="test.hibernate" >
<class name="Child" table="child" where="status!='DELETED'">
<id name="id" />
<natural-id>
<property name="cid" />
</natural-id>
<property name="name" />
</class>
</hibernate-mapping>