-->
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: attach a detached object and interceptor
PostPosted: Thu Jul 27, 2006 11:24 am 
Newbie

Joined: Tue Feb 21, 2006 10:31 am
Posts: 7
Hi all,
I'm implementing an Audit interceptor and everything works but one thing: I always have to historize all the properties
I won't annoy you with the onFlushDirty previousState=null problem beacause I understood that the problem is in having only the updated object in session.

Now I read the interesting http://www.hibernate.org/161.html but integrating it in my application would be so laborious to justify this other intersting approach http://blog.hibernate.org/cgi-bin/blosx ... ggers.html that's also laborious

Now, also if it's not advised as the best pratice I would like to attach my before-update object to the session in order to have the previous state populated. I tried lots of solutions like

old = session.get(Foo.class, new.getId());
session.evict(old);
session.update(new);

but the previous state in the interceptor was still null (and I need it to persist only the changes)

I read lots of messages over the net but none was clear.

If I will solve this I will submit all my Audit interceptor to give others having my same problem (lots of persons) a working example that should work in most cases (as the AOP philosophy wants).

thx in advance for any clue

LUCA

I'm using Hibernate 3.1


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 26, 2006 6:39 am 
Beginner
Beginner

Joined: Tue Sep 16, 2003 11:26 am
Posts: 25
Location: Berlin - Germany
Hi LUCA,

Use
Code:
session.merge( entity )
. If you use merge previousState is not null anymore when onFlushDirty of interceptor is called.

You find documentation about merge in chapter 10 of the Reference Documentation:
http://www.hibernate.org/hib_docs/v3/reference/en/html/objectstate.html#objectstate-detached

n2/Daniel.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 11, 2006 7:26 am 
Newbie

Joined: Tue Feb 21, 2006 10:31 am
Posts: 7
hi n2,
thx for your reply and sorry form my long delay but I gave up with oldValues problem.

Today I tried with session.merge but oldValues is still null....

what version are you using?

LUCA


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 11, 2006 9:32 am 
Beginner
Beginner

Joined: Tue Sep 16, 2003 11:26 am
Posts: 25
Location: Berlin - Germany
xlucax wrote:
...
what version are you using?
...

I am using Hibernate 3.1.3, Java 1.4 on Linux. My DBMS is MS Sqlserver.
n2


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 19, 2006 2:19 pm 
Newbie

Joined: Tue Feb 21, 2006 10:31 am
Posts: 7
I tried with session.merge but oldValues is still 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.