-->
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: Interceptor::findDirty function
PostPosted: Wed May 24, 2006 1:04 pm 
Newbie

Joined: Tue Apr 25, 2006 9:49 am
Posts: 9
Hi
I'm trying to use findDirty function of Interceptor interface to exclude some properties names from update query(i don't want them to be updated when function saveOrUpdate was called on entity). In order to accomplish that i'm returning from findDirty function array of indeces of all properties but this particular property name :
Code:
public int[] findDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState, String[] propertyNames, Type[] types) {
int [] ret_val=new int[propertyNames.length-1];
int j=0;
for (int i = 0; i < propertyNames.length; ++i) {
  if(!propertyNames[i].equalsIgnoreCase("image")){
   ret_val[j]=i;
   ++j;
  }
}
return ret_val;
}


The problem is that image column is still updated...
What am i doing wrong? Do i use findDirty method correctly?
Thanks


Top
 Profile  
 
 Post subject: Re: Interceptor::findDirty function
PostPosted: Wed May 24, 2006 8:55 pm 
Newbie

Joined: Fri Apr 15, 2005 7:52 pm
Posts: 13
If the index of the property "image" is 0, it will still get updated since your ret_val will contain one unused slot preinitialized to 0 (the local variable j is useless for what you're trying to do). You'd need a variable sized ArrayList for this which you convert to int[] at the end. Also, if you don't want to muck around with the indices you can instead try setting currentState[i] = previousState[i] if propertyNames[i].equals("image").

_________________
Tired of spam? => http://www.spamino.com


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.