-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Problem using Hierarchical Structure
PostPosted: Mon Sep 04, 2006 5:47 pm 
Regular
Regular

Joined: Sun Oct 26, 2003 9:02 pm
Posts: 90
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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 05, 2006 10:24 am 
Regular
Regular

Joined: Sun Oct 26, 2003 9:02 pm
Posts: 90
Changed the relationship inverse to false and it worked but shouldn't it work with inverse="true"?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.