-->
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: Delete cascade isn't working
PostPosted: Wed Jun 13, 2007 11:04 am 
Beginner
Beginner

Joined: Fri Sep 02, 2005 3:42 pm
Posts: 32
Hi,

I have this annotation mapping:

Code:

@oneToMany(mappedBy="category",cascade=CascadeType.ALL)
public Set<User> getUsers(){return users;}


But, when i try to remove the category i get the foreing key exception, Why Doesn't hibernate delete my relations when i try to delete this side of relationship? Could someone help me?

Alberto


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 13, 2007 3:48 pm 
Senior
Senior

Joined: Tue Jun 12, 2007 4:49 pm
Posts: 127
Location: India
Hi,

Cascade type all is cascade all except delete-orphan. If you want that then you would need to use delete orphan option in cascade type.

Regards,
Jitendra


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 13, 2007 4:31 pm 
Beginner
Beginner

Joined: Fri Sep 02, 2005 3:42 pm
Posts: 32
Thanks,

But in CascadeType Enum doesn't have a delete-orphan, Where can i found this type? I know there is in xml configuration. I found a CascadeStyle from hibernate packages but i would like to use the javax.persistence... Is it possible?

Alberto


Top
 Profile  
 
 Post subject: Re:
PostPosted: Thu Jun 14, 2007 3:30 am 
Senior
Senior

Joined: Tue Jun 12, 2007 4:49 pm
Posts: 127
Location: India
Which version of hibernate are you using?

This one has it:
[url]
http://www.hibernate.org/hib_docs/annot ... eType.html
[/url]

javax.persistence can be considered a kind of sub-set of hibernate, it will not have all the features present in hibernate annotations.

If you switch to mapping xmls then you will be able to use more of hibernate functionality.

Regards,
Jitendra


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 14, 2007 9:01 am 
Beginner
Beginner

Joined: Fri Sep 02, 2005 3:42 pm
Posts: 32
I tried to use this :



Code:

@OneToMany(mappedBy="departamento",cascade=CascadeType.ALL)      @Cascade(value={org.hibernate.annotations.CascadeType.DELETE_ORPHAN,org.hibernate.annotations.CascadeType.ALL})
public Set<Category> getCategorys();



But didn't work, Is that something wrong? Thanks for help me.

Alberto


Top
 Profile  
 
 Post subject: Re:
PostPosted: Thu Jun 14, 2007 9:28 am 
Senior
Senior

Joined: Tue Jun 12, 2007 4:49 pm
Posts: 127
Location: India
What is the error/exception?

Try putting only delete_orphan as option instead of both.

Regards,
Jitendra


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 14, 2007 10:44 am 
Beginner
Beginner

Joined: Fri Sep 02, 2005 3:42 pm
Posts: 32
It's an exception, i get a constrained violation when i tried to delete the one side because have references in other table for it.

Alberto


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 14, 2007 3:41 pm 
Senior
Senior

Joined: Tue Jun 12, 2007 4:49 pm
Posts: 127
Location: India
Which side are you trying to delete ? Can you follow the standard template for posting.


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.