-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate cascade deletion is making me mad
PostPosted: Fri Feb 12, 2010 4:01 am 
Newbie

Joined: Fri Feb 12, 2010 3:49 am
Posts: 2
Hello everybody !

I'm new and I'm here because I'm really out of solution on how to use hibernate for cascade deletion.

First, I've got a CMS-like part in my application.
But cascade deletion don't seem to work for my entities.

I've tried everything I could think of but nothing's working as I want. I tried:

- adding annotation "@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.ALL,org.hibernate.annotations.CascadeType.DELETE_ORPHAN})" after the @OneToMany annotation. From what I have read, it should tell Hibernate to delete child when deleting an entity but I still have some "ConstraintViolationException" coming out of my db connection.

- adding annotation "@OnDelete(action=OnDeleteAction.CASCADE)" after the @OneToMany (and/or @ManyToOne) annotation. To tell hibernate to generate the foreign key with the database option "on delete cascade". But my schema has nothing like that.

- manually delete the child rows before deleting the parent.

And nothing is working.
Has anyone found a solution working to do so ?

Please help me :'(


Top
 Profile  
 
 Post subject: Re: Hibernate cascade deletion is making me mad
PostPosted: Fri Feb 12, 2010 4:18 am 
Newbie

Joined: Fri Feb 12, 2010 3:49 am
Posts: 2
I just tried this one thing:

Code:
@OneToMany(mappedBy = "contenusPromo")
   @org.hibernate.annotations.Cascade({
      org.hibernate.annotations.CascadeType.ALL,
      org.hibernate.annotations.CascadeType.DELETE_ORPHAN
   })
   private List<BlocTextePromo> promotions = new ArrayList<BlocTextePromo>();


But I still get my lovely error:

Code:
org.hibernate.exception.ConstraintViolationException: could not execute update query

Code:
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`BLOC_TEXTE`, CONSTRAINT `FK8CDB44D71D9FF2F9` FOREIGN KEY (`CONTENT_ID`) REFERENCES `CONTENUS` (`CONTENT_ID`))


Top
 Profile  
 
 Post subject: Re: Hibernate cascade deletion is making me mad
PostPosted: Fri Feb 12, 2010 5:42 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
I think you need to include a cascade attribute in the @OneToMany annotation. At least that is what the documentation recommends: http://docs.jboss.org/hibernate/stable/ ... ec-cascade


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