@@ -0,0 +1,2068 @@
+package to.etc.domui.hibernate.types;%0A%0Aimport org.hibernate.HibernateException;%0Aimport org.hibernate.usertype.UserType;%0Aimport to.etc.util.DateUtil;%0A%0Aimport java.io.Serializable;%0Aimport java.sql.PreparedStatement;%0Aimport java.sql.ResultSet;%0Aimport java.sql.SQLException;%0Aimport java.sql.Types;%0Aimport java.util.Date;%0A%0A/**%0A * @author %3Ca href=%22mailto:jal@etc.to%22%3EFrits Jalvingh%3C/a%3E%0A * Created on 31-10-17.%0A */%0Apublic class DateNonnullType implements UserType %7B%0A%09@Override%0A%09public Object assemble(Serializable cached, Object owner) throws HibernateException %7B%0A%09%09return null;%0A%09%7D%0A%0A%09@Override%0A%09public Object deepCopy(Object value) throws HibernateException %7B%0A%09%09if(value == null)%0A%09%09%09return value;%0A%09%09return new Date(((java.util.Date) value).getTime());%0A%09%7D%0A%0A%09@Override%0A%09public Serializable disassemble(Object value) throws HibernateException %7B%0A%09%09return null;%0A%09%7D%0A%0A%09@Override%0A%09public boolean equals(Object x, Object y) throws HibernateException %7B%0A%09%09if(x != null)%0A%09%09%09return x.equals(y);%0A%09%09else%0A%09%09%09return x == y;%0A%09%7D%0A%0A%09@Override%0A%09public int hashCode(Object arg0) throws HibernateException %7B%0A%09%09return arg0.hashCode();%0A%09%7D%0A%0A%09@Override%0A%09public boolean isMutable() %7B%0A%09%09return true;%0A%09%7D%0A%0A%09@Override%0A%09public Object nullSafeGet(ResultSet resultSet, String%5B%5D names, Object owner) throws HibernateException, SQLException %7B%0A%09%09if(resultSet == null)%0A%09%09%09return null;%0A%09%09Date v = resultSet.getDate(names%5B0%5D);%0A%09%09if(resultSet.wasNull())%0A%09%09%09return null;%0A%09%09if(DateUtil.getYear(v) %3E= 9999)%0A%09%09%09return null;%0A%09%09return new java.util.Date(v.getTime());%0A%09%7D%0A%0A%09@Override%0A%09public void nullSafeSet(PreparedStatement statement, Object value, int index) throws HibernateException, SQLException %7B%0A%09%09Date dt = (Date) value;%0A%09%09if(null == dt) %7B%0A%09%09%09dt = DateUtil.dateFor(9999, 0, 1);%0A%09%09%7D%0A%09%09statement.setDate(index, new java.sql.Date(dt.getTime()));%0A%09%7D%0A%0A%09@Override%0A%09public Object replace(Object arg0, Object arg1, Object arg2) throws HibernateException %7B%0A%09%09return null;%0A%09%7D%0A%0A%09@Override%0A%09public Class%3C ? %3E returnedClass() %7B%0A%09%09return Date.class;%0A%09%7D%0A%0A%09@Override%0A%09public int%5B%5D sqlTypes() %7B%0A%09%09return new int%5B%5D%7BTypes.DATE%7D;%0A%09%7D%0A%7D%0A

Add Hibernate Type to store null Date values as 9999-01-01.