I implemented a Hibernate interceptor (extends EmptyInterceptor) and implemented the onFlushDirty method in order to set an object's property to null when that object is saved. The code looks like this:
public boolean onFlushDirty(...) {
// looking for the property index
int i = 0;
for (i=0; i<propertyNames.length; i++) {
if ("someProperty".equals(propertyNames[i])) {
break;
}
}
// setting it to null
currentState[i] = null;
Unfortunatelly, the record is still saved to the database even though i nullified the object. Strangely, when i modify that object, the change is save to the db.
Both the object and the property are entities.