File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Hibernate JPA and orphan deletion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate JPA and orphan deletion" Watch "Hibernate JPA and orphan deletion" New topic

Hibernate JPA and orphan deletion

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17421

This is more or less a Public Service Announcement. I'd report it directly to JBoss/Hibernate but their captcha system is apparently so dependent on one's having the right color vision and monitor characteristics that only spammers can get through it. I can't, so I can't re-activate my old account.

I have the questionable good fortune to be responsible for a system that commits the twin offences of having composite keys AND components of said keys are fixed-length character fields. Very often it bites me.

In this particular case, I think I'm encountering a bug in Hibernate JPA Version 3.6.4. I have a simple parent object associated bidirectionally one-to-many with a set of child objects. The relationship cascades all JPA operations, has orphanRemoval set "true" and just for good measure I attached the deprecated Hibernate-specific @Cascade orphan removal annotation.

When the parent object has children removed from its collection while detached and then a Spring transactional service method is invoked to merge the results back to the database, the operation appears to succeed. Unfortunately, appearances are deceiving. The returned merged object's child collection correctly reflects the removals, but the database does not.

Trying to cache the new/old states of the collection and manually update it can be a little tricky. Here's how I finally worked around the issue:

Anyone here who has a working Hibernate bug-reporting account, please feel free to pass this on. For the rest of us, at least I figure Google can spread the word.

An IDE is no substitute for an Intelligent Developer.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63869

[OFF TOPIC] Heh. Yeah, I recently gave up on joining a technical forum after failing five attempts to get through their ridiculous captcha system.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Hibernate JPA and orphan deletion
It's not a secret anymore!