tag:blogger.com,1999:blog-7692212329376878812.post6705961110269152402..comments2013-10-16T18:51:35.335+03:00Comments on The Java Redemption: Where is "delete-orphans" ?Anonymoushttp://www.blogger.com/profile/17356379670827963689noreply@blogger.comBlogger12125tag:blogger.com,1999:blog-7692212329376878812.post-70597933985494123652011-02-17T16:35:05.925+02:002011-02-17T16:35:05.925+02:00@Anonymous It seems my post has been an inspiratio...@Anonymous It seems my post has been an inspiration for others!Anonymoushttps://www.blogger.com/profile/17356379670827963689noreply@blogger.comtag:blogger.com,1999:blog-7692212329376878812.post-82646557848573521072011-02-17T15:59:14.531+02:002011-02-17T15:59:14.531+02:00Have a look at this - http://jbossguru.com/archive...Have a look at this - http://jbossguru.com/archives/45Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7692212329376878812.post-61700159845657531922010-07-29T08:18:10.557+03:002010-07-29T08:18:10.557+03:00JPA 2.0 now supports the "orphanRemoval=true&...JPA 2.0 now supports the "orphanRemoval=true" attribute in the @xxxToMany annotation, adding it does the trickUnknownhttps://www.blogger.com/profile/02494882852943777373noreply@blogger.comtag:blogger.com,1999:blog-7692212329376878812.post-61332214123225094462010-05-17T21:11:14.154+03:002010-05-17T21:11:14.154+03:00another scenario: Suppose the Customer has many Ph...another scenario: Suppose the Customer has many PhoneNumbers:<br />@OneToMany(cascade=CascadeType.ALL)<br />private Set phoneNumbers;<br /><br />If you update one of the PhoneNumbers, and then call merge() the Customer, the old PhoneNumber remains in the database as an orphan, and the updated PhoneNumber is added to the database, linked to the Customer. Delete orphans handles this too. Because my app has this as a scenario, I prefer to add the annotation:<br /><br />@OneToMany(...)<br />@org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)<br />private Set phoneNumbers;Brianhttps://www.blogger.com/profile/14237431036767765599noreply@blogger.comtag:blogger.com,1999:blog-7692212329376878812.post-8680060283404863952009-05-22T00:52:17.038+03:002009-05-22T00:52:17.038+03:00My database has a constraint saying that the forei...My database has a constraint saying that the foreign key (from child to parent) cannot be NULL. After I remove the child via hibernate by hand (which by the way removes the row from the DB), the next time I flush the entity manager I get a hibernate exception saying that the foreign key in my child table cannot be NULL. How can I avoid this exception? Any ideas?<br /><br />Thanks,kjhttps://www.blogger.com/profile/17909110771326855694noreply@blogger.comtag:blogger.com,1999:blog-7692212329376878812.post-20771735353952186602008-08-28T11:46:00.000+03:002008-08-28T11:46:00.000+03:00@adnanraza No straightforward way. You either dele...@adnanraza No straightforward way. You either delete "by hand" or use implementation specific annotations (e.g. hibernate)Anonymoushttps://www.blogger.com/profile/17356379670827963689noreply@blogger.comtag:blogger.com,1999:blog-7692212329376878812.post-60494451659488342008-08-28T11:32:00.000+03:002008-08-28T11:32:00.000+03:00I am also in the same boat, I have tried a lot to ...I am also in the same boat, I have tried a lot to make it delete its children when merging but it does'nt work. Is there any way so can I delete???????Unknownhttps://www.blogger.com/profile/13990189786110161047noreply@blogger.comtag:blogger.com,1999:blog-7692212329376878812.post-48705790459126173022007-10-31T23:25:00.000+02:002007-10-31T23:25:00.000+02:00@Victor:Or you can use xml for the hibernate speci...@Victor:<BR/>Or you can use xml for the hibernate specific configuration and thus keep your source code completely independent.Anonymoushttps://www.blogger.com/profile/17356379670827963689noreply@blogger.comtag:blogger.com,1999:blog-7692212329376878812.post-42250577397268649072007-10-30T03:12:00.000+02:002007-10-30T03:12:00.000+02:00Hey, I am in the same boat. Took me hours of googl...Hey, I am in the same boat. Took me hours of googling to figure out why Cascade deletes were not working on child instances.I was really pissed at hibernate at first until I found out it was a JPA limitation. Ended up with the former solution since the latter forces me to create DAOs for the child pojos, which just creates extra unnecessary code. Furthermore, I don't think it is a big deal since annotations don't bind it to hibernate when compiled, it is just meta data afterall.victorihttps://www.blogger.com/profile/14189384509808749049noreply@blogger.comtag:blogger.com,1999:blog-7692212329376878812.post-27437488185143574992007-10-25T19:47:00.000+03:002007-10-25T19:47:00.000+03:00That case was something I hadn't thought about. As...That case was something I hadn't thought about. As a matter of fact I have started using hibernate annotations in more cases latelyAnonymoushttps://www.blogger.com/profile/17356379670827963689noreply@blogger.comtag:blogger.com,1999:blog-7692212329376878812.post-47526886267553906912007-10-25T19:21:00.000+03:002007-10-25T19:21:00.000+03:00Yes I agree with you, the second approach is bette...Yes I agree with you, the second approach is better in case when you would like to avoid dependencies to specific JPA implementations. But it's very problematic in some cases. For example if you are using merge operation and you do not know which entities have been removed from collection. It's why I personally use the first one.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7692212329376878812.post-3206506821112182362007-04-27T15:44:00.000+03:002007-04-27T15:44:00.000+03:00I do the second as well. As you said no delete orp...I do the second as well. As you said no delete orphan. If a child 'dies' you have to programmatically remove the connection from the parent.<BR/><BR/>In complex db schemas with lots of graph connections, I agree this might be..a bit problematic..in terms of development and maintenance!javapapohttps://www.blogger.com/profile/12972241246613222894noreply@blogger.com