Is there a setting in hibernate to ignore null values of properties when saving a hibernate object?
NOTE
In my case I am de-serial
I have googled a lot about this,but there is no the very solution for me.So,I used a not graceful solution to cover it.
public void setAccount(Account a) throws HibernateException {
try {
Account tmp = (Account) session.
get(Account.class, a.getAccountId());
tmp.setEmail(getNotNull(a.getEmail(), tmp.getEmail()));
...
tmp.setVersion(getNotNull(a.getVersion(), tmp.getVersion()));
session.beginTransaction();
session.update(tmp);
session.getTransaction().commit();
} catch (HibernateException e) {
logger.error(e.toString());
throw e;
}
}
public static T getNotNull(T a, T b) {
return b != null && a != null && !a.equals(b) ? a : b;
}
I receive an Object a which contains a lot of fields.Those field maybe null,but I don't want to update them into mysql.
I get an tmp Obejct from db, and change the field by method getNotNull,then update the Object.
a Chinese description edition