-->
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.  [ 6 posts ] 
Author Message
 Post subject: why update, not delete when I use cascade
PostPosted: Tue Aug 15, 2006 3:02 am 
Newbie

Joined: Tue Aug 15, 2006 2:53 am
Posts: 5
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.1.3

Mapping documents:

Code between sessionFactory.openSession() and session.close():no

Full stack trace of any exception that occurs:no

Name and version of the database you are using:oracle 9i

The generated SQL (show_sql=true):
update
course
where
studid=?

delete
student
where
id=?

Debug level Hibernate log excerpt:


Last edited by byronlilu on Tue Aug 15, 2006 3:12 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 15, 2006 3:10 am 
Newbie

Joined: Tue Aug 15, 2006 2:53 am
Posts: 5
my table for example is fellowed:
table:student
id
name

table:course
id
name
studid
(id -----studid)


I am crazy for this problem, I tried many way , but i failed.
The following is the segment of my student.hbm.xml:
<set name="courses" inverse="false" lazy="true" cascade="all">
<key column="studid" not-null="true"/>
<one-to-many class="course"/>
</set>

I deeped into hibernate source, I find the boolean marking whether the collection is deleted is alwayse false, so the sql is update, not delete.

any guy can give me a hand!!!!!!!!


Last edited by byronlilu on Tue Aug 15, 2006 9:35 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 15, 2006 7:01 am 
Newbie

Joined: Tue Aug 15, 2006 5:38 am
Posts: 2
Location: Ukraine
try to use
cascade="all-delete-orphan"


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 15, 2006 9:41 pm 
Newbie

Joined: Tue Aug 15, 2006 2:53 am
Posts: 5
first thank you.
I tried all-delete-orphan, but this problem still there.

in my source , code like this:
//begintranscation

Student student = new Student();
student.setId(XXXX);// this xxxx means a valid value and exist in my table student.
session.delete(student);

// commit

is any wrong in my code?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 16, 2006 1:54 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Yes, that code won't enable cascading deletes. Try this, instead:
Code:
//begintranscation

Student student = session.load(Student.class, XXXX);
if (student != null)
{
  session.delete(student);
}

// commit

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 28, 2006 3:30 am 
Newbie

Joined: Tue Aug 15, 2006 2:53 am
Posts: 5
tenwit wrote:
Yes, that code won't enable cascading deletes. Try this, instead:
Code:
//begintranscation

Student student = session.load(Student.class, XXXX);
if (student != null)
{
  session.delete(student);
}

// commit


thank you very very much!

i tried, the result is OK!


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