Usually you do the inverse thing: a null value set in the bean will be set in a default value in database.
You get this using
default attribute within
column element inside a
property element:
Code:
<property name="property">
<column name="PROPERTY_VALUE" default="..." />
</property>
Instead, if you want to set an attribute with a default value, in case in the database there is a null value in corresponding field, I think the best way is to modify your setter methods like this:
Code:
private final static Object DEFAULT_VALUE = ...;
private Object property;
public void setProperty(Object property) {
if (property == null) {
property = DEFAULT_VALUE;
}
}
Pay attention that in this way, you cannot ever have a null value for your property: do you want this?
Daniele
Code: