-->
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.  [ 3 posts ] 
Author Message
 Post subject: OnPreUpdate event not allowing insert to seperate table
PostPosted: Tue Feb 23, 2010 10:36 am 
Newbie

Joined: Tue Feb 23, 2010 10:00 am
Posts: 3
Hi,

I have a Company Table and a CompanyChangeLog table. Whenever a change is made to the Company table I would like to insert a row into the CompanyChangeLog table. All my database access is being performed by NHibernate. I am trying to perform the write to the CompanyChangeLog in the OnPreUpdate event handler which is executed whenever a update is made to Company table.

I perform an update on the Company Table, the OnPreUpdate event handler executes, the code within it to insert to the CompanyChangeLog executes. After this I check the database and I can see the change I made to Company, but no row has been inserted into CompanyChangeLog. Also, no exceptions were encountered.

In debugging this I tried copying the code to insert to CompanyChangeLog from the OnPreUpdate event handler to the aspx page so that it executes after OnPreUpdate is finished. This worked, however, I get 2 rows inserted, not just 1. This is because at the time this code executes, it also adds the row I tried to add within the OnPreUpdate event handler.


Top
 Profile  
 
 Post subject: Re: OnPreUpdate event not allowing insert to seperate table
PostPosted: Tue Feb 23, 2010 10:40 am 
Newbie

Joined: Tue Feb 23, 2010 10:00 am
Posts: 3
It is as if any updates made within an OnPreUpdate event handler, to a seperate table from the one that generarted the event, are not commited until a write to that table is made from outside the event handler. If I do not try and perform a write outside the event handler, my insert is lost and never persisted.

Has anyone else encountered this?


Top
 Profile  
 
 Post subject: Re: OnPreUpdate event not allowing insert to seperate table
PostPosted: Thu Feb 25, 2010 11:52 am 
Newbie

Joined: Tue Feb 23, 2010 10:00 am
Posts: 3
I found the solution. The audit write must be performed by a separate session. Have a look here viewtopic.php?f=1&t=932065


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