-->
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.  [ 3 posts ] 
Author Message
 Post subject: Force pdate SQL statement
PostPosted: Wed Apr 13, 2005 3:33 pm 
Regular
Regular

Joined: Thu Aug 19, 2004 9:28 am
Posts: 63
Hi,

When updating a Status column on a table, an update trigger is executed.

The problem is, I want Hibernate to generate the Update SQL statement even if the Status column value doesn't really change (DB value:"N", New value: "N").

It's a Legacy system and that how things were done... Is there a way to set the column's dirty flag or to tell Hibernate to generate the update statement no matter what?

Thanks


Hibernate version:
version 2.1.6, 9.8.2004


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 13, 2005 11:47 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Sure. Apply a custom net.sf.hibernate.Interceptor; especially see the findDirty() method.

[url]
http://www.hibernate.org/hib_docs/api/n ... ang.Object[],java.lang.Object[],java.lang.String[],net.sf.hibernate.type.Type[])
[/url]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 14, 2005 1:48 pm 
Newbie

Joined: Thu Apr 14, 2005 1:31 pm
Posts: 1
Thanks for your reply Steve.

I implemented an Interceptor as suggested. I turned Hibernate showsql ON and I can see that the Update sql is generated but, that's the last thing that gets executed... (it freezes on me)

Looks like my findDirty() method doesn't return the right value(s).


My hibernate.Form table has 12 columns (one identity column), so this is returning an array containing 11 indices. Do I need to do anything else for this to work?

Thanks

Here my Interceptor: (I took out the unnecessary code/methods)



public class FormStatusInterceptor implements Interceptor {

public int[] findDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState,
String[] propertyNames, net.sf.hibernate.type.Type[] types) {

String className = entity.getClass().toString();

int[] results = null;
int count = 0;
if (className.equalsIgnoreCase("class hibernate.Form")) {
for (int i = 0; i < types.length; i++) {
if (results == null) {
results = new int[types.length];
}
results[count++] = i;
}
}

if (count == 0) {
return null;
} else {
int[] trimmed = new int[count];
System.arraycopy(results, 0, trimmed, 0, count);

System.out.println("FormStatusInterceptor - returning int[] : " + trimmed.length);

return trimmed;
}
}

...

}


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