-->
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.  [ 6 posts ] 
Author Message
 Post subject: Persisting Collections After Rollback / Lions Escape Cage!
PostPosted: Mon Nov 08, 2010 6:26 pm 
Newbie

Joined: Thu Jul 05, 2007 2:31 pm
Posts: 5
Configuration: Spring 2.5.6, Hibernate 3.6.0

Supposed I have 2 objects:
  • Cage
  • Lion
where Cage owns a set of Lion.

Here's the annotation on Cage:
Code:
@OneToMany(fetch=FetchType.EAGER) @JoinColumn(name="owner_id")
@org.hibernate.annotations.Cascade(value={org.hibernate.annotations.CascadeType.DELETE_ORPHAN, org.hibernate.annotations.CascadeType.ALL})
private Set<Lion> getLions()


Here's what I'm trying to do / how I'm reproducing the bug:
1. Create a transient Cage that has a single object in its set, Lion
2. Attempt to persist Cage - a validation exception is thrown from within the transaction, causing the transaction to rollback
3. Fix the validation error
4. Attempt to persist Cage again - This time the transaction completes successfully, but the owner_id entry in Lion is missing. Orphaned Lion without a cage is not good!

From some searching, it sounds like hibernate and rollback do not work well together. I'm trying to understand why, and if there's a work-around (other than performing a deep-copy beforehand).

Why would this be happening? Each of the 2 persist attempts is a separate context (I'm seeing a separate log message "org.hibernate.impl.SessionImpl - opened session at timestamp XXXXX" at the beginning of each JPA transaction), and the Java object doesn't appear to be changed after the first/failed commit.

This means that there must be state about the collection being stored elsewhere? Any tips on where to look?

I also observed:
When the relationship is a SET, the owner_id is missing.
When the relationship is a LIST, the row in the join table is missing.

Thanks!
Mike

Related topics / articles:
http://weblogs.java.net/blog/2007/04/27/jpa-and-rollbacks-not-pretty
https://forum.hibernate.org/viewtopic.php?t=943975


Top
 Profile  
 
 Post subject: Re: Persisting Collections After Rollback / Lions Escape Cage!
PostPosted: Wed Nov 10, 2010 3:05 pm 
Newbie

Joined: Fri Nov 13, 2009 2:47 pm
Posts: 3
I'm also seeing something similar, any headway on this mike?


Top
 Profile  
 
 Post subject: Re: Persisting Collections After Rollback / Lions Escape Cage!
PostPosted: Mon Nov 15, 2010 10:56 am 
Newbie

Joined: Thu Jul 05, 2007 2:31 pm
Posts: 5
I haven't been able to track this down yet. Still digging through the source code with logging set to trace.

Do any of the hibernate developers have any suggestions about where to focus my search?

Thanks!
Mike


Top
 Profile  
 
 Post subject: Re: Persisting Collections After Rollback / Lions Escape Cage!
PostPosted: Wed Dec 08, 2010 11:26 am 
Newbie

Joined: Fri Nov 13, 2009 2:47 pm
Posts: 3
I'm also really in need of this fix / ideas. Hibernate gurus?


Top
 Profile  
 
 Post subject: Re: Persisting Collections After Rollback / Lions Escape Cage!
PostPosted: Thu Dec 09, 2010 12:00 pm 
Newbie

Joined: Wed Oct 06, 2010 1:35 pm
Posts: 6
I can add that I have seen this behavior also. We are still using Hibernate 3.31 - are you using the latest or an older version?


Top
 Profile  
 
 Post subject: Re: Persisting Collections After Rollback / Lions Escape Cage!
PostPosted: Mon Dec 13, 2010 12:58 pm 
Newbie

Joined: Thu Jul 05, 2007 2:31 pm
Posts: 5
I originally hit this issue with hibernate 3.3.0 SP1. Today I tested the latest (3.6.0) and I'm still seeing the issue.

Any idea what could be going on?

Thanks!


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