-->
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.  [ 2 posts ] 
Author Message
 Post subject: How to get the cascade details?
PostPosted: Fri May 19, 2006 6:59 am 
Newbie

Joined: Fri May 19, 2006 5:45 am
Posts: 1
Hi All,
I am currently using Hibernate version 3.0 with Spring 1.2.5 for a web based application. I have a requirement, described below, for which I would like a solution using Hibernate if possible.
I need to use cascade logical delete(or cascade update) feature thats available in Hibernate. But before the cascade action needs to be executed, I need to get the information of all the entities that refer this instance upfront - their class type and if they are logically deleted or not - instead, an instance of all the entities referencing this instance would be adequate.
Based on the type of the referencing or associated entities I need to decide if the cascade update should be allowed or not.
Eg:- Company is associated with Address and User. I need to get all the instances of Address and User in case I need to logically delete Company. Only if the user instances are all already logically deleted, I can delete this Company instance but if there are only Address references, which are all active, then I can delete the Company as Address is not a very significant record in our application and can get logically deleted cascadingly. Supposing that Company can be allowed to be deleted, I will have to get the user(user of the application)'s confirmation before proceeding to do it.
Can I achieve this using Hibernate 3.0? If yes, then kindly give me pointers as to how this can be achieved. How can I retrieve the information even before a cascade is actually executed?
Any help is appreciated.

Regards and TIA,
Deepa


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 19, 2006 9:05 am 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
Enable bi-directional relation between company and user.

You can check

Code:
if ( company.getUsersCollection().isEmpty() ) {
    session.delete( company ); // this will also remove address'es with cascade
}


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