-->
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.  [ 5 posts ] 
Author Message
 Post subject: Interceptor, detached sessions
PostPosted: Thu Apr 22, 2004 9:25 am 
Newbie

Joined: Thu Apr 22, 2004 9:16 am
Posts: 3
Location: Boston
hi,

We want to implement minimal audit logging. We've implemented
an Interceptor overiding the onFlushDirty method. The previousState
during this method call is always null.

We are using pojo's from detached sessions. The pojo is created in
one session, modified in the web-tier and then sent to the biz tier where
a new session is created and the object is updated.

I read in other posts that this is the reason why the previousState is null

Is there a workaround to it?

thanks
Ram


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 3:38 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
since reattaching using update will always update, then

Code:
session.load(oldObject, webObject.getId());
//Do your comparison
session.evict(oldObject);
update(webObject);

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 5:00 pm 
Newbie

Joined: Thu Apr 22, 2004 9:16 am
Posts: 3
Location: Boston
Do you mean that I instantiate another session in my Interceptor? and then
do the comparison like you suggested.

Wouldnt that be a performance hit? since you would be creating a new
session through the factory in your interceptor.

A quick thought, out architecture plans us to use "optimistic locking with
automatic versioning" feature of hibernate. To do this wouldnt Hibernate
need to load the old state of the object being updated to do the version
check? Does this mean that with this feature turned on my previous state
would be not-null?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 6:58 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
rampi wrote:
Do you mean that I instantiate another session in my Interceptor? and then do the comparison like you suggested.

Hum, I did not realize you do that in an interceptor.
In this *particular* case, an interceptor is useless since you actually know that you'll update the object.
To be honest, I've never tryed that at all and never think of a session call inside an interceptor.

rampi wrote:
Wouldnt that be a performance hit? since you would be creating a new session through the factory in your interceptor.

I don't think so, a session is light and you can reuse the same underlying conenction than in your initial session.

rampi wrote:
To do this wouldnt Hibernate
need to load the old state of the object being updated to do the version
check?

No
Code:
update ... where version=?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 07, 2004 12:15 pm 
Newbie

Joined: Thu Apr 22, 2004 9:16 am
Posts: 3
Location: Boston
[quote="emmanuel"]
Hum, I did not realize you do that in an interceptor.
In this *particular* case, an interceptor is useless since you actually know that you'll update the object.
To be honest, I've never tryed that at all and never think of a session call inside an interceptor.

I didnt want to create another session in the interceptor. Ended up
implementing onLoad in the interceptor as well. During the business
method did the following

Code:
session.load(oldObject, webObject.getId());
session.evict(oldObject)
session.update(webObject);


The interceptor's onLoad method stored the state in a hashmap and
when update was called, had the old state if previous state was null


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