-->
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.  [ 8 posts ] 
Author Message
 Post subject: Deletion of 3-level bi-directional association
PostPosted: Thu Aug 28, 2003 5:58 am 
Regular
Regular

Joined: Wed Aug 27, 2003 2:55 am
Posts: 90
Location: Sweden
Hello,

Following object structure have its associations mapped as bi-directional with cascade="all".

[Object_A] 1--* [Object_B] 1--* [Object_C]

If I map Object_B -> Object_C as bi-directional and Object_A -> Object_B as not bi-directional a delete on topmost Object_A is working great.

When I map both association as bi-directional I get a HibernateException with message "SQL update or deletion failed (row not found)"!

I've set debug level to DEBUG and Hibernate says: "deleting a transient instance" about all instances, should that consern me?

This is the code performing the delete:

Code:
MyClass object = session.load(MyClass.class, id);
session.delete(object);


Kind regards, Andreas


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2003 6:04 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
nowhere near enough information.....


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2003 7:05 am 
Regular
Regular

Joined: Wed Aug 27, 2003 2:55 am
Posts: 90
Location: Sweden
Where can I read about the minimum?

Class_A.hbm.xml

Code:
<hibernate-mapping>
    <class name="Class_A" table="A" dynamic-update="true" dynamic-insert="true">

<id name="a_guid" column="a_guid" type="string" unsaved-value="null">
    <generator class="GUIDGenerator"/>
</id>

// Properties

<set name="bs" cascade="all" inverse="true">
    <key column="_guid"/>
    <one-to-many class="Class_B"/>
</set>


Class_B.hbm.xml

Code:
<hibernate-mapping>
    <class name="Class_B" table="B" dynamic-update="true" dynamic-insert="true">

<id name="b_guid" column="b_guid" type="string" unsaved-value="null">
    <generator class="GUIDGenerator"/>
</id>

// Properties except for a_guid (foreign key)

<many-to-one name="parent" column="a_guid" cascade="all" not-null="true"/>

<set name="cs" cascade="all" inverse="true">
    <key column="b_guid"/>
    <one-to-many class="Class_C"/>
</set>


Class_C.hbm.xml

Code:
<hibernate-mapping>
    <class name="Class_C" table="C" dynamic-update="true" dynamic-insert="true">

<id name="c_guid" column="c_guid" type="string" unsaved-value="null">
    <generator class="GUIDGenerator"/>
</id>

// Properties except for a_guid (foreign key)

<many-to-one name="parent" column="b_guid" cascade="all" not-null="true"/>


Code snippet:

Code:
Class_A object = session.load(Class_A.class, guid);
session.delete(object);


And log message:

Code:
12:44:59,128 DEBUG SessionImpl:413 - opened session
12:44:59,128 DEBUG JDBCTransaction:36 - begin
12:44:59,128 DEBUG SessionImpl:896 - deleting a transient instance
12:44:59,128 DEBUG SessionImpl:941 - deleting [Class_A#{2C90AA1E-00F7-00F7-0001-FFFFF747EB3E}]
12:44:59,128 DEBUG Cascades:336 - processing cascades for: Class_A
12:44:59,128 DEBUG Cascades:275 - cascading to collection: Class_A.bs
12:44:59,143 DEBUG Cascades:55 - cascading to delete()
12:44:59,143 DEBUG Cascades:237 - unsaved-value strategy NULL
12:44:59,143 DEBUG SessionImpl:896 - deleting a transient instance
12:44:59,143 DEBUG SessionImpl:941 - deleting [Class_B#2C90AA1E-00F7-00F7-0002-FFFFF747EB3E]
12:44:59,143 DEBUG Cascades:237 - unsaved-value strategy NULL
12:44:59,143 DEBUG Cascades:336 - processing cascades for: Class_B
12:44:59,143 DEBUG Cascades:275 - cascading to collection: Class_B.cs
12:44:59,143 DEBUG Cascades:55 - cascading to delete()
12:44:59,143 DEBUG Cascades:237 - unsaved-value strategy NULL
12:44:59,143 DEBUG SessionImpl:896 - deleting a transient instance
12:44:59,143 DEBUG SessionImpl:941 - deleting [Class_C#2C90AA1E-00F7-00F7-0003-FFFFF747EB3E]
12:44:59,143 DEBUG Cascades:336 - processing cascades for: Class_C
12:44:59,143 DEBUG Cascades:344 - done processing cascades for: Class_C
12:44:59,143 DEBUG Cascades:336 - processing cascades for: Class_C
12:44:59,159 DEBUG Cascades:55 - cascading to delete()
12:44:59,159 DEBUG SessionImpl:927 - deleting a persistent instance
12:44:59,159 DEBUG SessionImpl:930 - object was already deleted
12:44:59,159 DEBUG Cascades:344 - done processing cascades for: Class_C
12:44:59,175 DEBUG Cascades:344 - done processing cascades for: Class_B
12:44:59,190 DEBUG Cascades:336 - processing cascades for: Class_B
12:44:59,190 DEBUG Cascades:55 - cascading to delete()
12:44:59,190 DEBUG Cascades:237 - unsaved-value strategy NULL
12:44:59,190 DEBUG SessionImpl:896 - deleting a transient instance
12:44:59,190 DEBUG SessionImpl:941 - deleting [Class_A#2C90AA1E-00F7-00F7-0001-FFFFF747EB3E]
12:44:59,190 DEBUG Cascades:336 - processing cascades for: Class_A
12:44:59,190 DEBUG Cascades:275 - cascading to collection: Class_A
12:44:59,190 DEBUG Cascades:55 - cascading to delete()
12:44:59,190 DEBUG SessionImpl:927 - deleting a persistent instance
12:44:59,190 DEBUG SessionImpl:930 - object was already deleted
12:44:59,190 DEBUG Cascades:55 - cascading to delete()
12:44:59,190 DEBUG Cascades:237 - unsaved-value strategy NULL
12:44:59,190 DEBUG SessionImpl:896 - deleting a transient instance
12:44:59,190 DEBUG SessionImpl:941 - deleting [Class_B#2C90AA1E-00F7-00F7-000A-FFFFF747EB3E]
12:44:59,190 DEBUG Cascades:336 - processing cascades for: Class_B
12:44:59,206 DEBUG Cascades:275 - cascading to collection: Class_B.cs
12:44:59,206 DEBUG Cascades:55 - cascading to delete()
12:44:59,206 DEBUG Cascades:237 - unsaved-value strategy NULL
12:44:59,206 DEBUG SessionImpl:896 - deleting a transient instance
12:44:59,206 DEBUG SessionImpl:941 - deleting [Class_C#2C90AA1E-00F7-00F7-000B-FFFFF747EB3E]
12:44:59,206 DEBUG Cascades:336 - processing cascades for: Class_C
12:44:59,206 DEBUG Cascades:344 - done processing cascades for: Class_C
12:44:59,206 DEBUG Cascades:336 - processing cascades for: Class_C
12:44:59,206 DEBUG Cascades:55 - cascading to delete()
12:44:59,221 DEBUG SessionImpl:927 - deleting a persistent instance
12:44:59,221 DEBUG SessionImpl:930 - object was already deleted
12:44:59,221 DEBUG Cascades:344 - done processing cascades for: Class_C
12:44:59,237 DEBUG Cascades:344 - done processing cascades for: Class_B
12:44:59,237 DEBUG Cascades:336 - processing cascades for: Class_B
12:44:59,237 DEBUG Cascades:55 - cascading to delete()
12:44:59,237 DEBUG SessionImpl:927 - deleting a persistent instance
12:44:59,237 DEBUG SessionImpl:930 - object was already deleted
12:44:59,237 DEBUG Cascades:344 - done processing cascades for: Class_B
12:44:59,237 DEBUG Cascades:344 - done processing cascades for: Class_A
12:44:59,237 DEBUG Cascades:336 - processing cascades for: Class_A
12:44:59,237 DEBUG Cascades:344 - done processing cascades for: Class_A
12:44:59,237 DEBUG Cascades:344 - done processing cascades for: Class_B
12:44:59,253 DEBUG Cascades:55 - cascading to delete()
12:44:59,253 DEBUG SessionImpl:927 - deleting a persistent instance
12:44:59,253 DEBUG SessionImpl:930 - object was already deleted
12:44:59,253 DEBUG Cascades:344 - done processing cascades for: Class_A
12:44:59,253 DEBUG Cascades:336 - processing cascades for: Class_A
12:44:59,253 DEBUG Cascades:344 - done processing cascades for: Class_A
12:44:59,253 DEBUG JDBCTransaction:54 - commit
12:44:59,253 DEBUG SessionImpl:2011 - flushing session
12:44:59,253 DEBUG SessionImpl:2113 - Flushing entities and processing referenced collections
12:44:59,253 DEBUG SessionImpl:2397 - Processing unreferenced collections
12:44:59,253 DEBUG SessionImpl:2602 - Collection dereferenced: [Class_B.cs#2C90AA1E-00F7-00F7-0002-FFFFF747EB3E]
12:44:59,253 DEBUG SessionImpl:2602 - Collection dereferenced: [Class_B.cs#2C90AA1E-00F7-00F7-000A-FFFFF747EB3E]
12:44:59,253 DEBUG SessionImpl:2602 - Collection dereferenced: [Class_A.bs#2C90AA1E-00F7-00F7-0001-FFFFF747EB3E]
12:44:59,253 DEBUG SessionImpl:2602 - Collection dereferenced: [Class_A.bs#{2C90AA1E-00F7-00F7-0001-FFFFF747EB3E}]
12:44:59,268 DEBUG SessionImpl:2408 - Scheduling collection removes/(re)creates/updates
12:44:59,268 DEBUG SessionImpl:2023 - Flushed: 0 insertions, 0 updates, 16 deletions to 16 objects
12:44:59,268 DEBUG SessionImpl:2028 - Flushed: 0 (re)creations, 0 updates, 8 removals to 8 collections
12:44:59,268 DEBUG SessionImpl:2058 - executing flush
12:44:59,268 DEBUG BatcherImpl:166 - about to open: 0 open PreparedStatements, 0 open ResultSets
12:44:59,300 DEBUG EntityPersister:548 - Deleting entity: Class_C#2C90AA1E-00F7-00F7-0003-FFFFF747EB3E
12:44:59,300 DEBUG BatcherImpl:166 - about to open: 0 open PreparedStatements, 0 open ResultSets
12:44:59,300 DEBUG SessionFactoryImpl:526 - prepared statement get: delete from class_c where c_guid=?
Hibernate: delete from class_c where c_guid=?
12:44:59,346 DEBUG SessionFactoryImpl:536 - preparing statement
12:44:59,346 DEBUG StringType:44 - binding '2C90AA1E-00F7-00F7-0011-FFFFF747EB3E' to parameter: 1
12:44:59,346 DEBUG EntityPersister:548 - Deleting entity: Class_B#2C90AA1E-00F7-00F7-0002-FFFFF747EB3E
12:44:59,346 DEBUG BatcherImpl:173 - done closing: 0 open PreparedStatements, 0 open ResultSets
12:44:59,346 DEBUG SessionFactoryImpl:554 - closing statement
12:44:59,346 DEBUG BatcherImpl:166 - about to open: 0 open PreparedStatements, 0 open ResultSets
12:44:59,346 DEBUG SessionFactoryImpl:526 - prepared statement get: delete from class_b where b_guid=?
Hibernate: delete from class_b where b_guid=?
12:44:59,346 DEBUG SessionFactoryImpl:536 - preparing statement
12:44:59,346 DEBUG StringType:44 - binding '2C90AA1E-00F7-00F7-0002-FFFFF747EB3E' to parameter: 1
12:44:59,362 DEBUG EntityPersister:548 - Deleting entity: Class_A#2C90AA1E-00F7-00F7-000B-FFFFF747EB3E
12:44:59,362 DEBUG BatcherImpl:173 - done closing: 0 open PreparedStatements, 0 open ResultSets
12:44:59,362 DEBUG SessionFactoryImpl:554 - closing statement
12:44:59,362 DEBUG BatcherImpl:166 - about to open: 0 open PreparedStatements, 0 open ResultSets
12:44:59,362 DEBUG SessionFactoryImpl:526 - prepared statement get: delete from class_c where c_guid=?
Hibernate: delete from class_c where c_guid=?
12:44:59,378 DEBUG SessionFactoryImpl:536 - preparing statement
12:44:59,378 DEBUG StringType:44 - binding '2C90AA1E-00F7-00F7-0010-FFFFF747EB3E' to parameter: 1
12:44:59,393 DEBUG EntityPersister:548 - Deleting entity: Class_B#2C90AA1E-00F7-00F7-000A-FFFFF747EB3E
12:44:59,393 DEBUG BatcherImpl:173 - done closing: 0 open PreparedStatements, 0 open ResultSets
12:44:59,393 DEBUG SessionFactoryImpl:554 - closing statement
12:44:59,393 DEBUG BatcherImpl:166 - about to open: 0 open PreparedStatements, 0 open ResultSets
12:44:59,393 DEBUG SessionFactoryImpl:526 - prepared statement get: delete from class_b where b_guid=?
Hibernate: delete from class_b where b_guid=?
12:44:59,393 DEBUG SessionFactoryImpl:536 - preparing statement
12:44:59,393 DEBUG StringType:44 - binding '2C90AA1E-00F7-00F7-000A-FFFFF747EB3E' to parameter: 1
12:44:59,393 DEBUG EntityPersister:548 - Deleting entity: Class_A#2C90AA1E-00F7-00F7-0001-FFFFF747EB3E
12:44:59,393 DEBUG BatcherImpl:173 - done closing: 0 open PreparedStatements, 0 open ResultSets
12:44:59,393 DEBUG SessionFactoryImpl:554 - closing statement
12:44:59,393 DEBUG BatcherImpl:166 - about to open: 0 open PreparedStatements, 0 open ResultSets
12:44:59,393 DEBUG SessionFactoryImpl:526 - prepared statement get: delete from class_a where a_guid=?
Hibernate: delete from class_a where a_guid=?
12:44:59,425 DEBUG SessionFactoryImpl:536 - preparing statement
12:44:59,425 DEBUG StringType:44 - binding '2C90AA1E-00F7-00F7-0001-FFFFF747EB3E' to parameter: 1
12:44:59,425 DEBUG EntityPersister:548 - Deleting entity: Class_A#{2C90AA1E-00F7-00F7-0001-FFFFF747EB3E}
12:44:59,425 DEBUG StringType:44 - binding '{2C90AA1E-00F7-00F7-0001-FFFFF747EB3E}' to parameter: 1
12:44:59,440 DEBUG SessionImpl:447 - transaction completion
common.exceptions.ComponentException: java.lang.reflect.InvocationTargetException
   at middle.CommandControllerImpl.doCommand(CommandControllerImpl.java:78)
   at nico.presentation.PersistenceManager.deleteCase(PersistenceManager.java:41)
   at nico.presentation.HibernateClient.delete(HibernateClient.java:107)
   at nico.presentation.HibernateClient.start(HibernateClient.java:642)
   at nico.presentation.HibernateClient.main(HibernateClient.java:666)
Caused by: java.lang.reflect.InvocationTargetException
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at middle.CommandControllerImpl.doCommand(CommandControllerImpl.java:61)
   ... 4 more
Caused by: common.exceptions.ComponentException: Failed deleting Class_A
   at integration.dao.Class_ADataManagerImpl.delete(Class_ADataManagerImpl.java:66)
   at business.Class_AController.delete(Class_AController.java:21)
   ... 9 more
Caused by: net.sf.hibernate.HibernateException: SQL update or deletion failed (row not found)
   at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25)
   at net.sf.hibernate.persister.EntityPersister.delete(EntityPersister.java:575)
   at net.sf.hibernate.impl.ScheduledDeletion.execute(ScheduledDeletion.java:22)
   at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2100)
   at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2066)
   at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2005)
   at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:57)
   at integration.dao.Class_ADataManagerImpl.delete(Class_ADataManagerImpl.java:62)
   ... 10 more


/Andreas


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2003 8:13 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Quote:
Where can I read about the minimum?


The "Forum & Mailinglist" page on the Hibernate website explains what is required.

Quote:
<set name="bs" cascade="all" inverse="true">
<key column="_guid"/>
<one-to-many class="Class_B"/>
</set>


That should be "a_guid", not "_guid".

Do you really require

- your own UUID generator instead of the Hibernate builtins?
- dynamic update and inserts?

Your code and mapping is good.[/quote]

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2003 8:34 am 
Regular
Regular

Joined: Wed Aug 27, 2003 2:55 am
Posts: 90
Location: Sweden
Hello Christian,

The "_guid" is a typo. I'm using dummie objects in my mapping not to reveal my business objects to you guys ;-)

Need my own UUID generator cause the formatting in your UUIDGenerator is different.

Dynamic inserts/updates for performance? All my classes use dynamic insert/update, that cannot be the problem?


Regards, Andreas


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2003 4:06 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Why does the toplevel Class_A instance sometimes return


{2C90AA1E-00F7-00F7-0001-FFFFF747EB3E}


as its id, and other times just:

2C90AA1E-00F7-00F7-0001-FFFFF747EB3E



Are you doing something dodgy in your get/set pair?



(This is the reason why Hibernate tries to delete it *twice*; it thinks its a different instance.)


Actually! I think the reason is that you have 2 different instances of Class_A floating around in the object graph.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 29, 2003 5:04 am 
Regular
Regular

Joined: Wed Aug 27, 2003 2:55 am
Posts: 90
Location: Sweden
The differences in the two (the same) GUID is because I assign (with UUIDGEnerator) the GUID without the '{', but the database adds them when stored.

Then how can I get rid of all instances associated with the session and then try to delete the object structure?

The db handles a GUID with or without the '{' as same.

Nothing specially is done in the set/get methods.

I think you're on to something here... ;-)

Regards, Andreas


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 29, 2003 5:30 am 
Regular
Regular

Joined: Wed Aug 27, 2003 2:55 am
Posts: 90
Location: Sweden
Tested some things and found that when I try to call session.load(class, guid), with a GUID not having the '{' a exception is thrown:


Syntax error converting from a character string to uniqueidentifier


Works fine if I use the '{'. All the other instances inside the topmost object, when performing "cascade loading", gets the GUID from database without the '{'.

How can I get around this problem (if it is a problem)?

PS. The uniqueidentifier type is a must!

Regards, Andreas


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