I have been working several hours on creating a list within a list in hibernate. I have a parent object with a list of children, and each child can have a list associated with it.
Parent table parentid, (several fields) From the mapping: <list name="children" table="child_1" cascade="all"> <key column="parentId"/> <index column="listIndex"/> <one-to-many class="test.Child1"/> </list>
Child 1 table: id (auto-incremented), parentId (links to parent table), name, description, listIndex From the mapping: <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping> <class name="test.Child1" table="child_1"> <id name="id" column="id" type="long"> <generator class="increment"/> </id> <property name="name"/> <property name="description"/> <list name="values" table="child_value"> <key column="id"/> <index column="listIndex"/> <many-to-many column="value" class="test.Value"/> </list> </class>
</hibernate-mapping> <!-- parsed in 0ms -->
Child 2 table: id (links to child table's id), value (links to another table), listIndex (linked from other mapping)
Everything worked fine until I added the id column and third table. I had it more or less working, but was getting hibernate errors every other transaction (problems with all-delete-orphan, which was not solved by clearing the list, and manually deleting the items didn't work either). I would like to implement a double layered list, but I would like to eliminate the "id" column from the first child table. Is there a clean way to do this? Like, for instance, is there any way I could implement the third child to have the link to id and listIndex of the first child table, coupled with a listIndex2 as a composite key of 3?
|