-->
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.  [ 1 post ] 
Author Message
 Post subject: After rollback, insert events fired but delete events not...
PostPosted: Wed Aug 13, 2008 4:44 am 
Newbie

Joined: Fri Aug 01, 2008 12:13 am
Posts: 4
Hibernate version: 3.3.0 CR1

Name and version of the database you are using: MS SQL Server 2005

Mapping documents: (Irrelevant bits removed)

Code:
<hibernate-mapping>
  <session-factory>
        <event type="post-insert">
            <listener class="com.x.y.z.HibernateEventListener"/>
        </event>
        <event type="pre-delete">
            <listener class="com.x.y.z.HibernateEventListener"/>
        </event>
  </session-factory>
</hibernate-mapping>


Description:

I'm using post-insert and pre-delete events to synchronize some external data with one of my mapped entities. I am creating new entities by instantiating them then calling persist(). I am running into problems where the post-insert event is triggered and then, later on in the same transaction if something causes an error and the transaction must be rolled back, the pre-delete event is not triggered. When this happens my data goes all out of sync. I.e.:

1. Instantiate new mapped entity.
2. Call persist().
3. Hibernate generates INSERT statements, post-insert happens - sync external data.
4. Do some other stuff that causes an error.
5. Error causes transaction to be rolled back.
6. Since transaction is rolled back, INSERT statements don't apply, but also pre-delete event is not fired. External data goes out of sync.

It is hard for me to do the external data sync without using hibernate events because:

1. I don't always explicitly delete the mapped entities -- they are frequently deleted by delete-orphan cascades.
2. When stuff fails in #4 above, I don't have enough information conveniently available to know what needs to be done to clean up -- only hibernate knows which entities it's rolling back.

What is the cleanest and most convenient way to do this? Is there some sort of event that is triggered when uncommitted mapped entities are rolled back? Is there some way to configure pre-delete (or even post-delete would be acceptable) to fire when a transaction is rolled back?

Thanks,
Jason


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.