-->
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.  [ 7 posts ] 
Author Message
 Post subject: cascade="none" question?
PostPosted: Wed Nov 05, 2003 12:43 pm 
Regular
Regular

Joined: Tue Oct 14, 2003 11:11 pm
Posts: 62
Location: Brasil/Curitiba
Hi,

I have a one-to-many relationship beteween Team and Player where cascade=none

Code:
<set name="players" cascade="none" inverse="false" lazy="true">
             <key column="team_id" />
         <one-to-many class="hibernate.PlayerVO" />
</set>


In the following code, I loaded a Team from database and deleted it.

Code:
TeamVO t = new TeamVO();
session.load(t, new Long(62));
session.delete(t);


But Hibernate set "null" in the "team_id" column in the Player table.
But why this code doesn't throw an exception ? like this:

"ORA-02292: integrity constraint (SCOTT.FKE294C1B2AA36363D) violated - child".

You can't remove a parent that contains children.

cascade is set to "none", so why is this happening?

Hibernate: select teamvo0_.team_id as team_id, teamvo0_.team_name as team_name, teamvo0_.city as city from teams teamvo0_ where teamvo0_.team_id=?
Hibernate: update players set team_id=null where team_id=?
Hibernate: delete from teams where team_id=?

thanks very much!

_________________
Ricardo Lecheta


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 05, 2003 4:23 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
I suppose cascade attribute is not for specifying referential integrity rules. It is only to tell Hibernate which children objects must be persisted when you persist parent object.

Why don't you want to set RI constraints within DB?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 05, 2003 5:17 pm 
Regular
Regular

Joined: Tue Oct 14, 2003 11:11 pm
Posts: 62
Location: Brasil/Curitiba
ok, but if i execute a query with JDBC an Exception is threw:

for example:

Statement stmt = connection.createStatement();
stmt.execute("delete from parent.....");

"ORA-02292: integrity constraint (SCOTT.FKE294C1B2AA36363D) violated - child".

then, the hibernate should do the samething :-)

_________________
Ricardo Lecheta


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 05, 2003 5:17 pm 
Regular
Regular

Joined: Tue Oct 14, 2003 11:11 pm
Posts: 62
Location: Brasil/Curitiba
Ricardo wrote:
ok, but if i execute a query with JDBC an Exception is throw:

for example:

Statement stmt = connection.createStatement();
stmt.execute("delete from parent.....");

"ORA-02292: integrity constraint (SCOTT.FKE294C1B2AA36363D) violated - child".

then, the hibernate should do the samething :-)

_________________
Ricardo Lecheta


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 05, 2003 5:36 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
I suppose this is because of inverse="false"


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 05, 2003 7:23 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Your parent_id column of child hasn't a not null constraint, so Hibernate set it to null and after that delete parent.
Hibernate does that because parent is responsible of the association (inverse=false)

In your plain SQL, you delete parent wo deferencing childs.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 06, 2003 1:01 pm 
Regular
Regular

Joined: Tue Oct 14, 2003 11:11 pm
Posts: 62
Location: Brasil/Curitiba
thank you guys !

it worked :-)

_________________
Ricardo Lecheta


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