How do I cascade delete a collection in Hibernate?

You need to adjust your mappings. Try making the Post property of comment not null and marking the Comments property of post as inverse.

You need to adjust your mappings. Try making the Post property of comment not null and marking the Comments property of post as inverse. Component persistent="true" table="post" { property name="Id" fieldtype="id"; property name="Comments" fieldtype="one-to-many" cfc="Comment" fkcolumn="post_id" cascade="all" inverse="true"; } component persistent="true" table="comment" { property name="Id" fieldtype="id"; property name="Post" fieldtype="many-to-one" cfc="Post" column="post_id" notnull="true"; }.

I applied this to my tests and it started performing as expected. – Adam Tuttle Sep 23 at 19:21.

You'll have to make post_id in Comment table nullable in your DB. That's how hibernate does cascade delete. It'll set all Comments with post_id = 13 as null, then delete all comments where post_id IS NULL.

I'm pretty sure this isn't the solution, considering that doing so breaks referential integrity. – Daniel T. Sep 23 at 0:40 I'd like to know if there's a better way too if there is one.

– Henry Sep 23 at 0:57 Inspired by this answer and its comments, I did a pretty thorough investigation of the configuration options and posted the results on my blog: fusiongrokker. Com/post/on-cascaded-hibernate-deletes -- ultimately, after all of the different configuration combinations I tested, I found that there's no way to get bernate to run something like delete from comment where blog=1; delete from blog where id=1' without using something like HQL. So it's possible to get the desired result, just not by using entityDelete().

– Adam Tuttle Sep 23 at 16:25.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions