views:

151

answers:

2

In our application we are pulling data from a DB2 mainframe database. If the database has "low values" in a field, hibernate sends a "null" value in the object. This occurs even if the column is defined as "not null".

As we are doing XML parsing on this, Castor is having trouble with it. I would like to fix this in Hibernate. Also, all of the hibernate hbm files are generated, so we can't mess with them (they are regened from time to time.)

Any way to intercept all Strings and replace nulls with ""?

A: 

You can use hibernate interceptor which extends EmptyInterceptor to perform the operation you want to before actually firing that query.

the example given here might help you

http://www.mkyong.com/hibernate/hibernate-interceptor-example-audit-log/

GK
I believe this does not fire on Select statements...
sliver
+1  A: 
  • Create a custom user type to replace null with ""
  • Put the user type name where you normally put a hibernate type name in reveng.xml.
Pascal Thivent
This was our first thought and the one we will probably implement so far. I was hoping for a Dialect or configuration change, but this might be the best we can get. Thanks!
sliver
@sliver I'm not aware of something like that at the dialect level (this tweak seems too specific to be in the dialect) but I may be wrong. My feeling is that a UserType is the way to implement this.
Pascal Thivent