-->
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.  [ 2 posts ] 
Author Message
 Post subject: Help needed using findDirty in Interceptor
PostPosted: Mon Sep 08, 2008 5:45 pm 
Newbie

Joined: Mon Sep 08, 2008 5:19 pm
Posts: 5
Hibernate version: 3.2.6.ga

Hello, I'm trying to use an Interceptor, and I haven't been able to find the answers to a couple of (seemingly) basic questions. I've got things configured OK, my Interceptor is being called when I expect.

1) In the documentation for Interceptor.findDirty(), the return value is described as:
The return value determines whether the entity is updated

* an array of property indices - the entity is dirty
* an empty array - the entity is not dirty
* null - use Hibernate's default dirty-checking algorithm

The last two are clear. But what about the first case? How long should the array be? What should be in each element? Or is it OK to always return a single-element array containing a 0?

2) For the methods Interceptor.onSave() and onFlushDirty(), is it OK to call methods on the first parameter (entity) that might change the value of fields that will be persisted? Or is it only legal to change the values of the state or currentState parameters?

I'd appreciate any help -- my experiments haven't answered these questions yet, although I'm still working on it....


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 09, 2008 2:06 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Quote:
How long should the array be? What should be in each element?


The length of the array is determined by the number of properties that are dirty. Each element is an index to the Object[] that was passed to the findDirty() method.

Quote:
Or is it OK to always return a single-element array containing a 0?


INot always I think. If you have mapped your class with dynamic-update="true" I think Hibernate needs the indexes to be able to generate the proper SQL statement. There may be other reasons as well, so it is probably safer to try to return the correct index values.

Quote:
is it OK to call methods on the first parameter (entity) that might change the value of fields that will be persisted? Or is it only legal to change the values of the state or currentState parameters?


I really don't know, but my feeling is that as long the method call doesn't cause lazy initialization of proxies or collections it may not do any harm, but I wouldn't expect the changed properties to get persisted to the database.


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