Can Hibernate default a Null String to Empty String

markthegrea picture markthegrea · Apr 14, 2010 · Viewed 12.7k times · Source

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 ""?

Answer

Pascal Thivent picture Pascal Thivent · Apr 14, 2010
  • 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.