Benutzerdefinierten UserType in den Ruhezustand versetzen funktioniert nicht

Ich habe einen UserType (siehe unten) erstellt, um eine Situation in unserer mySQL-Datenbank zu behandeln, in der wir Nulldaten als 0000-00-00 00:00:00 gespeichert haben.

Wenn ich versuche, meine Entität mit einer Null für dispDT zu speichern (siehe unten), wird folgende Ausnahme generiert: "javax.persistence.PersistenceException: org.hibernate.PropertyValueException: Die Eigenschaft not-null verweist auf eine Null oder einen vorübergehenden Wert: myEntity.dispDt"

Durch Setzen eines Haltepunkts in jeder Methode in MySQLTimeStampUserType kann ich sehen, dass sie die deepCopy-Methode aufruft und niemals die nullSafeSet-Methode. Ich dachte, der Sinn der nuyllSafeSet-Methode besteht darin, den Wert zu manipulieren, bevor er beibehalten wird. Was mache ich falsch?

Entitätsanmerkungen

@Basic(optional = false)
@Column(name = "disp_dt")
@Type(type = "mypackage.MySQLTimeStampUserType")
//    @Temporal(TemporalType.TIMESTAMP)
private Date dispDt;

Benutzertyp-Klasse

public class MySQLTimeStampUserType implements UserType {

private static final int[] SQL_TYPES = {Types.TIMESTAMP};

public int[] sqlTypes() {
    return SQL_TYPES;
}

public Class returnedClass() {
    return Date.class;
}

public boolean equals(Object x, Object y) throws HibernateException {
    if (x == y) {
        return true;
    } else if (x == null || y == null) {
        return false;
    } else {
        return x.equals(y);
    }

}

public int hashCode(Object arg0) throws HibernateException {
    throw new UnsupportedOperationException("Not supported yet.");
}

public Object nullSafeGet(ResultSet resultSet, String[] names, Object owner) throws HibernateException, SQLException {
    // if the date is 0000-00-00 00:00:00 return null, else return the timestamp
    Date result = null;
    if (!resultSet.wasNull()) {
        if (!resultSet.getString(names[0]).equals("0000-00-00 00:00:00")) {
            result = resultSet.getDate(names[0]);
        }
    }
    return result;
}

public void nullSafeSet(PreparedStatement statement, Object value, int index) throws HibernateException, SQLException {
    // if the date is null set the value to "0000-00-00 00:00:00" else save the timestamp
    if (value == null) {
        statement.setString(index, "0000-00-00 00:00:00");
    } else {
        statement.setTimestamp(index,(Timestamp) value);
    }

}

public Object deepCopy(Object value) throws HibernateException {
    return value;
}

public boolean isMutable() {
    return false;
}

public Serializable disassemble(Object value) throws HibernateException {
    throw new UnsupportedOperationException("Not supported yet.");
}

public Object assemble(Serializable cached, Object owner) throws HibernateException {
    throw new UnsupportedOperationException("Not supported yet.");
}

public Object replace(Object original, Object target, Object owner) throws HibernateException {
    return original;
}
}

Antworten auf die Frage(3)

Ihre Antwort auf die Frage