| 
					
						 Hi ya,
 
 we have a simple parent child situation - where we want to have children ordered in specific order. For this we have children defined in a list and have defined an integer index column.
 
 Everything works ok - except if we add constraint to the database to the index column to be NOT NULL. While debugging what Hibernate does I noticed following:
 
 1)  insert into nodes (title, state, parent_id, owner_group_id, id) values (?, ?, ?, ?, ?)
 
 2) Hibernate: update nodes set parent_id=null, position=null where parent_id=? and position=?
 
 3) Hibernate: update nodes set parent_id=?, position=? where id=?
 
 I don't get it why Hibernate does the step 2 and is there anything that can be done. 
 
 Any pointers would be appreciated.
 
 Hibernate version: 
 
 2.1.3
 
 Mapping documents:
 
  <class name="fi.hy.sitetree.Node" table="nodes" >
 
         <cache usage="transactional"/>
 
         <id name="id" column="id" type="long" unsaved-value="0">
             <generator class="sequence">
                 <param name="sequence">node_seq</param>
             </generator>
         </id>
         
         <many-to-one name="parent" class="fi.hy.sitetree.Node" column="parent_id" not-null="true" />
 
         <list name="children" lazy="true" cascade="delete"  inverse="true">
             <cache usage="transactional"/>
             <key column="parent_id" />
             <index column="position" type="int" not-null="true" />
             <one-to-many class="fi.hy.sitetree.Node" />            
         </list>
 
 CREATE TABLE nodes (
     ID			NUMBER PRIMARY KEY,
     title		VARCHAR(255),
     parent_id		NUMBER REFERENCES nodes (ID) ON DELETE CASCADE,
     state		INTEGER DEFAULT 0,
     position		INTEGER DEFAULT 0 NOT NULL,
     owner_group_id	NUMBER REFERENCES principal_groups (ID)
 --    CONSTRAINT parent_position UNIQUE (parent_id, position)
 );
 
 public class Node {
 
     public static final String NODE_NAME = "Node";
 
     private long id;
     private String title;
     private NodeState state;
     private Node parent;
     private List children;
     private PrincipalGroup group;
 
     public void addChild(Node child) {
         if (children == null) {
             children = new Vector();
         }
         child.setParent(this);
         children.add(child);
     }
 
 ...
 
 }
 
 Name and version of the database you are using:
 
 Oracle 8
 
 The generated SQL (show_sql=true):
 
  insert into nodes (title, state, parent_id, owner_group_id, id) values (?, ?, ?, ?, ?)
 
 Hibernate: update nodes set parent_id=null, position=null where parent_id=? and position=?
 
 Hibernate: update nodes set parent_id=?, position=? where id=? 
											 _________________ -huima
					
  
						
					 |