-->
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.  [ 3 posts ] 
Author Message
 Post subject: throws ObjectDeletedException
PostPosted: Wed Dec 08, 2004 9:20 am 
Newbie

Joined: Wed Dec 08, 2004 8:56 am
Posts: 12
Location: China ChengDu
Hibernate version:2.1.6

AutoInfo.hbm.xml(children)
<hibernate-mapping package="bo">
<class name="AutoInfo" table="auto_info">
<id
column="AUTO_ID"
name="Id"
type="integer"
unsaved-value="null"
>
<generator class="native" />
</id>
<property
column="LICENSE_PLATE"
length="20"
name="LicensePlate"
not-null="false"
type="string"
/>
<many-to-one
class="People"
name="OwnerNo"
not-null="true"
>
<column name="OWNER_NO" />
</many-to-one>
</class>
</hibernate-mapping>

People.hbm.xml(parent)
<hibernate-mapping package="bo">
<class name="People" table="people">
<id
column="OWNER_ID"
name="Id"
type="integer"
unsaved-value="null"
>
<generator class="native" />
</id>
<property
column="NAME"
length="50"
name="Name"
not-null="false"
type="string"
/>
<property
column="ADDRESS"
length="255"
name="Address"
not-null="false"
type="string"
/>
<set inverse="true" cascade="all" name="AutoInfoSet">
<key column="OWNER_NO" />
<one-to-many class="AutoInfo" />
</set>
</class>
</hibernate-mapping>

Configuration cfg = new Configuration().configure();
SessionFactory sessions = cfg.buildSessionFactory();
Session session = sessions.openSession();
Transaction tx = session.beginTransaction();
ai =
(AutoInfo) session.find(
"from AutoInfo where LICENSE_PLATE='A00002'").get(
0);
session.delete(ai);
tx.commit();
session.close();


net.sf.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): 2, of class: bo.AutoInfo


MySQL 4.0.21

Hibernate: select autoinfo0_.AUTO_ID as AUTO_ID, autoinfo0_.LICENSE_PLATE as LICENSE_2_, autoinfo0_.OWNER_NO as OWNER_NO from auto_info autoinfo0_ where (LICENSE_PLATE='A00002' )
Hibernate: select people0_.OWNER_ID as OWNER_ID0_, people0_.NAME as NAME0_, people0_.ADDRESS as ADDRESS0_ from people people0_ where people0_.OWNER_ID=?
Hibernate: select autoinfose0_.OWNER_NO as OWNER_NO__, autoinfose0_.AUTO_ID as AUTO_ID__, autoinfose0_.AUTO_ID as AUTO_ID0_, autoinfose0_.LICENSE_PLATE as LICENSE_2_0_, autoinfose0_.OWNER_NO as OWNER_NO0_ from auto_info autoinfose0_ where autoinfose0_.OWNER_NO=?



Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 08, 2004 11:05 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
You are deleteing only the child of a parent-child relation. This is fine if you don't have cascade="all". If you want to keep the cascade="all" you have to remove the reference from the parent Set as well.

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 09, 2004 2:29 am 
Newbie

Joined: Wed Dec 08, 2004 8:56 am
Posts: 12
Location: China ChengDu
Use the same Mapping XML files,That two tables moved in Oracle 8i.

Hibernate: select autoinfo0_.AUTO_ID as AUTO_ID, autoinfo0_.LICENSE_PLATE as LICENSE_2_, autoinfo0_.OWNER_NO as OWNER_NO from auto_info autoinfo0_ where (LICENSE_PLATE='A00001' )
Hibernate: select people0_.OWNER_ID as OWNER_ID0_, people0_.NAME as NAME0_, people0_.ADDRESS as ADDRESS0_ from people people0_ where people0_.OWNER_ID=?
Hibernate: select autoinfose0_.OWNER_NO as OWNER_NO__, autoinfose0_.AUTO_ID as AUTO_ID__, autoinfose0_.AUTO_ID as AUTO_ID0_, autoinfose0_.LICENSE_PLATE as LICENSE_2_0_, autoinfose0_.OWNER_NO as OWNER_NO0_ from auto_info autoinfose0_ where autoinfose0_.OWNER_NO=?
Hibernate: delete from auto_info where AUTO_ID=?


Successfully deleted child record.
well,The biggest difference were: all operation depend on Spring Framework.

getHibernateTemplate().delete(persistable);


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