-->
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.  [ 4 posts ] 
Author Message
 Post subject: Parent/child - using list, hibernate updates index to null
PostPosted: Tue Oct 12, 2004 9:54 am 
Newbie

Joined: Fri Sep 17, 2004 7:33 am
Posts: 5
Location: Europe
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


Top
 Profile  
 
 Post subject: This is something that seems to be caused by SpringFramework
PostPosted: Thu Oct 14, 2004 4:10 am 
Newbie

Joined: Fri Sep 17, 2004 7:33 am
Posts: 5
Location: Europe
When trying to do a testcase that would produce the same behaviour in minimal enviroment, I noticed that this behaviour seems to be caused by Spring framework's HibernateTemplate. Not just Hibernate.

http://forum.springframework.org/viewto ... =5351#5351

_________________
-huima


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 14, 2004 6:13 am 
Newbie

Joined: Wed Feb 25, 2004 11:41 pm
Posts: 19
Location: China
Chapter 9. Parent Child Relationships in manual

hth

_________________
who can tell me why?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 14, 2004 6:57 am 
Newbie

Joined: Fri Sep 17, 2004 7:33 am
Posts: 5
Location: Europe
KaKaXi wrote:
Chapter 9. Parent Child Relationships in manual

hth


Did not really help, since that was already used as a base.

However for now we will circumvent the problem by setting constraint initially deferred, which prevents it to be checked untill transaction ends.

_________________
-huima


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.