-->
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.  [ 10 posts ] 
Author Message
 Post subject: deleting graphs of persistent object
PostPosted: Mon Feb 23, 2004 10:17 am 
Beginner
Beginner

Joined: Tue Jan 27, 2004 8:33 am
Posts: 29
Question 1: If a parent has a lazy collection of children, children are associated with cascade="all", and I delete the parent, what will happen?

a) hibernate fetches all children, then delete them one by one
b) hibernate delete all children without fetching them

And, in case of b), what if children have children mapped with cascade="all"?

Ex:
Class A holding a lazy collection of Bs, class B holding a lazy collection of Cs.
Each collection is mapped with cascade="all".
What happen when an A is deleted?

Question 2: Is there any difference in the delete process if I was using composite-ids?
I mean, suppose that in the case above I have:

A: id->A_ID in table A

B: id->B_ID, parent ID_A in table B

C: id->A_ID and B_ID (from table B as FK) and C_ID in table C

When I delete "a" I'd like something like this:

delete from C where A_ID = a
delete from B where A_ID = a
delete from A where A_ID = a

without any select, but I think I'm asking too much...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2004 4:46 am 
Beginner
Beginner

Joined: Tue Jan 27, 2004 8:33 am
Posts: 29
Why nobody replies?
Is this question too complicated? Too simple? Didn't I make myself clear?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2004 5:18 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
1. a.
2. no.

The lifecycle and cascade dependencies make Hibernate load objects before delete them.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 25, 2004 5:13 am 
Beginner
Beginner

Joined: Tue Jan 27, 2004 8:33 am
Posts: 29
Quote:
a) hibernate fetches all children, then delete them one by one

Damn... isn't the other solution (delete all children without fetching them)
preferable sometimes?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 25, 2004 6:18 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Of course, it just doesn't work that easy with ORM, we have to load it. However, finding a better solution is on the TODO list for a future version.

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 25, 2004 7:43 am 
Beginner
Beginner

Joined: Tue Jan 27, 2004 8:33 am
Posts: 29
Quote:
it just doesn't work that easy with ORM

Oh yes, I know, but Hibernate is so great that I expected some kind of miracle ;)

I think I'll go with the "persistent lifecycle callback".
Two more questions:
1) I don't like putting hibernate-code in my POJOs, so I think I will have to
extend my POJOs and implement Lifecycle. Wouldn't be better have a class-based "Interceptor" instead of a centralized one? Something like:

<class
[..]
interceptor="ThisClassInterceptor">


2) What happen if I delete through JDBC an object already loaded by Hibernate? Should I be careful in some particular occasion?

thank you


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 25, 2004 8:55 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
1. Have a look at the chained interceptor design pattern in the wiki area
2. Yes be careful, this is not expected by Hibernate.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 25, 2004 9:26 am 
Beginner
Beginner

Joined: Tue Jan 27, 2004 8:33 am
Posts: 29
Quote:
Have a look at the chained interceptor design pattern in the wiki area

1) Yes, this would solve my problem.
I would still prefer a "per-class" based solution in the configuration, though: if i get it right, with ChainedInterceptor I have to do something like:

Code:
ChainedInterceptor inter;
Interceptor[] interceptors;

// fill the array with every interceptor
[..]
inter.setInterceptors(interceptors)

cfg.setInterceptor(inter);

so every time I want to add an interceptor for a particular class I have to add it to the list of interceptors, rather then simply configure a persistent lifecycle callback class in the class configuration...

2) why some (a lot, actually) of the documents in the wiki area aren't well parsed? I mean, I can't print them properly because they are too "large" (the browser doesn't wrap the lines, I don't know why).

Thank you again.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 25, 2004 10:28 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
2. I've fixed Chained Interceptor. It's due to the <code/> that keep the line as it has been written. Feel free to fix others you can find :)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 18, 2004 7:26 pm 
Regular
Regular

Joined: Fri Dec 12, 2003 2:09 pm
Posts: 84
Location: San Francisco, USA
UltimoAmore wrote:
I would still prefer a "per-class" based solution in the configuration.


I concur. My Interceptor code has to inquire whether the entity implements certain interfaces, which is awkward. The Object[] arrays containing the new state, previous state, and so on, is also awkward.

With regards to the latter problem, it would be nice if Hibernate instead passed in an instance of the entity (newEntity) containing the new/previous state. Then the code could cast the entity to a specific Class and operate on it more directly... but, again, this suggests just providing an Interceptable interface that entities could implement.


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