-->
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.  [ 2 posts ] 
Author Message
 Post subject: Bizarre Envers side effect: collection gets deleted
PostPosted: Fri Jan 29, 2010 12:01 am 
Newbie

Joined: Tue Jul 07, 2009 11:18 am
Posts: 5
Location: Newton, MA
Hi. I am using Hibernate Envers 1.2.1, and recently encountered some bizarre behavior. It looks like a newly created collection is deleted after Envers does its thing on transaction commit. If I unwire AuditEventListener from the session factory, the collection is preserved. The entity whose collection is being deleted is not even being audited: the relationship is more like AuditedEntity -> PlainEntity -> collection. Here's the sequence of events I see:

1. Create AuditedEntity, establish many-to-one relationship with PlainEntity.
2. Add some elements to PlainEntity.someCollection.
3. Commit. I put a breakpoint in Hibernate's ActionQueue, and notice nothing unusual queued on flush.
4. After AuditEventListener does its work, ActionQueue now has instructions to blow away PlainEntity.someCollection.

Any suggestions on how I might diagnose this problem? Thanks.


Top
 Profile  
 
 Post subject: Re: Bizarre Envers side effect: collection gets deleted
PostPosted: Fri Jan 29, 2010 1:33 pm 
Newbie

Joined: Tue Jul 07, 2009 11:18 am
Posts: 5
Location: Newton, MA
I think I see what's going on. The collection in question is a @CollectionOfElements, so its lifecycle is entirely managed by the containing entity. I updated the collection by calling PlainEntity.setSomeCollection(new set). This orphaned the old collection. When Envers is wired in, it seems to disturb things around that the flushes execute the operations in the wrong order:

1. First, the new collection elements are inserted.

2. Later, somewhere during AuditSync.beforeCompletion, Hibernate realizes that the old collection was removed and notes this in the session's ActionQueue. It eventually issues a delete from ... statement. This leaves me with an empty collection.

I changed the collection operation to do:

plainEntity.getSomeCollection().clear();
plainEntity.getSomeCollection().addAll(new set);

That seems to work around the problem. Unfortunately, I don't really have the time to poke into this further to file a proper bug report. I thought I'd just write this followup to my original post in case it helps.


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