-->
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: Delete Cascade, with getHibernateTemplate().delete
PostPosted: Sun Oct 12, 2008 8:55 am 
Newbie

Joined: Thu Aug 14, 2008 5:30 pm
Posts: 2
Hi all,
I wanted to delete an entity, I am using getHibernateTemplate().delete(entity). It works fine except when I have an OneToOne association set.

Code:
//basic entity def and all things
class SomeObject{

//The rest of the code works fine
   @OneToOne(fetch=FetchType.LAZY)
    @Cascade( { CascadeType.ALL})    // I tried with CascadeType.DELETE  and DELETE_ORPHAN
    @ForeignKey(name="SOME_FK_COS_I_NEED_IT_IN_DB")
    private SomeOtherObject newObject;   

}


Now in my service when i try to call getHibernateTemplate().delete() it gives me error saying that SOME_FK_COS_I_NEED_IT_IN_DB constraint violated. So it is deleting SomeOtherObject even before deleting SomeObeject, how can I ask them do it opposit, ie delete SomeObject then SomeOtherObject


Hibernate version:3.2.3.ga


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 13, 2008 3:58 pm 
Newbie

Joined: Thu Aug 14, 2008 5:30 pm
Posts: 2
Can any one tell me ? how do cascade.delete work?


Well if I have an Entity A and which have an Entity B

like
Code:
@Entity
Class A{

    @OneToOne(fetch=FetchType.LAZY)
    @Cascade( { CascadeType.SAVE_UPDATE, CascadeType.DELETE})
    B b;
}


If I ask them to delete A, how will they delete?

Will they delete A then B, or remove Association with A and B Delete B and come back and delete A?

Well when i though both has there advantage and disadvantages
like if i delete A first I have to keep track of B, if there are n members all the n.

If the reverse is done then they have to remove association every time before deleting.


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.