Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.1.3
Mapping documents:
<hibernate-mapping>
<class name="OrganizationUnitTo" table="bp_organization_unit" lazy="false">
<id name="id" column="id" unsaved-value="0">
<generator class="sequence">
<param name="sequence">bp_sequence</param>
</generator>
</id>
<property name="name" column="name"/>
<property name="description" column="description"/>
<many-to-one name="parent" column="parent_id" class="OrganizationUnitTo"/>
<list name="children" lazy="true" cascade="all" inverse="true">
<key column="parent_id"/>
<index column="order_seq"/>
<one-to-many class="OrganizationUnitTo"/>
</list>
</class>
</hibernate-mapping>
Name and version of the database you are using: Oracle 10g Release 2
I'm using a hierarchical structure that stores organization units. Each organization unit has a parent and many children. I'm having problems when I'm trying to change an organization units parent.
// First get the objects
organizationUnit = (OrganizationUnitTo) session.get (OrganizationUnitTo.class, new Long (organizationUnitId));
parentOrganizationUnit = organizationUnit.getParent ();
intoOrganizationUnit = (OrganizationUnitTo) session.get (OrganizationUnitTo.class, new Long (intoOrganizationUnitId));
// Second remove the organization unit from the parent
children = parentOrganizationUnit.getChildren ();
children.remove (organizationUnit);
// Third add the organization unit to the new parent
intoOrganizationUnit.getChildren ().add (organizationUnit);
organizationUnit.setParent (intoOrganizationUnit);
The problem is that the organization is saved in the database with the same List index that it had before. So if it was stored on index 4 and I add the organization as a child of an empty organization unit, it will store it with index 4.
Regards,
Néstor Boscán