Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate JPA and orphan deletion

 
Tim Holloway
Saloon Keeper
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64713
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[OFF TOPIC] Heh. Yeah, I recently gave up on joining a technical forum after failing five attempts to get through their ridiculous captcha system.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic