-->
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.  [ 6 posts ] 
Author Message
 Post subject: Hibernate Interceptor onFlushDirty prevState[] is null
PostPosted: Tue Sep 09, 2008 3:46 pm 
Newbie

Joined: Mon Aug 25, 2008 8:39 am
Posts: 10
I am trying to compare old object values with new values using prevState parameters in hibernate interceptor function

public boolean onFlushDirty(Object entity, Serializable id, Object[] currState, Object[] prevState, String[] propertyNames, Type[] types) throws CallbackException


I have experienced that prevState parameter is always null.

Since it is null I retrieved the old state from database, however for the properties that are of collection type, the old state is already updated.

Any pointers on

1) why this prevState would be null
2) why would the collection property in database would already be in new state.


Top
 Profile  
 
 Post subject: Re: Hibernate Interceptor onFlushDirty prevState[] is null
PostPosted: Thu Sep 11, 2008 4:51 am 
Newbie

Joined: Thu Sep 11, 2008 4:46 am
Posts: 2
vjhiber wrote:
I am trying to compare old object values with new values using prevState parameters in hibernate interceptor function

public boolean onFlushDirty(Object entity, Serializable id, Object[] currState, Object[] prevState, String[] propertyNames, Type[] types) throws CallbackException


I have experienced that prevState parameter is always null.

Since it is null I retrieved the old state from database, however for the properties that are of collection type, the old state is already updated.

Any pointers on

1) why this prevState would be null
2) why would the collection property in database would already be in new state.



Hi ,

I have the same problem. Did you ever find an answer to this?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 11, 2008 5:08 am 
Pro
Pro

Joined: Tue Jun 12, 2007 4:13 am
Posts: 209
Location: Berlin, Germany
I do not know when previousState is null, but I think it is on an Insert operation. Because for my HistoryInterceptor where I'm just interested in changes compared to a previous version, I only evaluate
Code:
if (pCurrentState != null && null != pPreviousState) {


As this works for me, I do not have the experience that prevState
Quote:
is always null
!

_________________
Carlo
-----------------------------------------------------------
please don't forget to rate if this post helped you


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 11, 2008 11:15 am 
Newbie

Joined: Mon Aug 25, 2008 8:39 am
Posts: 10
I have found the prevState to be always null, whether its update/delete or insert.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2008 4:51 pm 
Pro
Pro

Joined: Tue Jun 12, 2007 4:13 am
Posts: 209
Location: Berlin, Germany
Okay, I forgot to say: I'm working with detached objects, and so, when I do the updates on the server, I call EntityManager.merge() on the object the client sent to me. On this call, Hibernate reloads the previous state from the database and does it's comparisions on dirty attributes/objects.

So, in this context, I always have previous state values.

_________________
Carlo
-----------------------------------------------------------
please don't forget to rate if this post helped you


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 15, 2008 11:52 am 
Newbie

Joined: Mon Aug 25, 2008 8:39 am
Posts: 10
Carlolf ..that makes sense. Probably that is the reason why prevState is null in my case, I am not doing a merge


Thank you all!


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