-->
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.  [ 4 posts ] 
Author Message
 Post subject: Object history tracking using PreUpdateEventListener
PostPosted: Thu Mar 24, 2005 9:37 am 
Newbie

Joined: Mon Mar 07, 2005 7:25 am
Posts: 10
Hi,

I'm trying to implement object history tracking using the Event handlers, as suggested by Christian to be a replacement for the "old" interceptor way.

The idea is to implement a PreUpdateEventListener that creates a "backup" of the old object state before doing the actual update. The easiest approach is to use the "oldState" fields, supplied by the PreUpdateEvent to create this "historical" new entry and this actually works.

However, when you use detached objects, the oldState of the object isn't available! This is logical in a way, but breaks the approach above.

What would be the best approach to actually read the "old" values in the database, without coming into conflict with the cache or overwriting the updates that have been made to the object? I've tried several approaches, but a lot of it runs into "possible nonthreadsafe access to session" errors or similar. It just doesn't seem possible to get the old state of an object after it has been modified.

Please help!
(Hibernate 3.0 RC1)


Top
 Profile  
 
 Post subject: oldState[] is null
PostPosted: Wed Jul 13, 2005 10:40 pm 
Newbie

Joined: Mon May 23, 2005 7:31 pm
Posts: 3
Does anybody know the answer to this?

It seems strange that the oldState property has been provided in both PreUpdateEvent and PostUpdateEvent even though it's never assigned a value.

J


Top
 Profile  
 
 Post subject: old state not always there..
PostPosted: Tue Nov 08, 2005 4:47 pm 
Newbie

Joined: Wed Feb 23, 2005 11:57 am
Posts: 15
On my app server, and in my unit tests the old state is set, but in my tapestry (web) app, its not set.

The old state is set from the EntityEntry getLoadedState() (in whatever makes the EntityUpdateAction).

In the EntityEntry object, the loaded state is set after a postUpdate call.

So I have a theory, that maybe the loaded state is not available if the update is called from a flush event.


The more I look inside this stuff, I see glaring architecture issues :(
Not saying I could do better but if your gonna have a public method called getOldState(), you should either:

(A) Explain in javadocs that the method is not reliable (i.e. so don't use it)
(B) Or fix the architecture so it will always give you the value it says it will

that event package has no documentation.

-gabe


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 29, 2008 2:44 pm 
Newbie

Joined: Tue Jan 29, 2008 2:38 pm
Posts: 2
Try doing the update using session.merge(). This should give you the oldState of the detached objects. You are likely to have troubles with the oldState of the embedded collections, however, or at least I do - the collection members are the same in the state and the oldState although they have been modified.


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