We are having a similar issue.
The interceptor is working perfectly in the add (onSave) case in which the records are added directly to the object. In the update case hibernate is not saving to the database the entries which are added during postFlush.
Our debugging shows the records have been added by the interceptor but they are not picked up and saved by hibernate.
Any suggestions for solving this problem would be greatly appreciated.
Code:
public void postFlush(Iterator it) throws CallbackException {
log.debug("Post-Flush");
while (it.hasNext()) {
Object obj = it.next();
if (!(obj instanceof Historizable)) {
continue;
}
Historizable h = (Historizable) obj;
Set newEntries = (Set) histories.get(h);
if (newEntries == null) {
continue;
}
h.getHistoryEntries().addAll(newEntries);
System.out.println("History Entries: ");
Iterator historiesIterator = h.getHistoryEntries().iterator();
while(historiesIterator.hasNext()){
System.out.println(historiesIterator.next());
}
}
histories.clear();
}
[banking-pilot] 2005-03-04 10:31:56,510 DEBUG [com.company.infrastructure.auditing.HistoryInterceptor] - <Post-Flush>
History Entries:
historyid: null
who: jbanker1
what: update
property: dateReceived
historyid: 11
who: jbanker1
what: created
property: null
historyid: null
who: jbanker1
what: update
property: dateEntered
[banking-pilot] 2005-03-04 10:31:56,511 DEBUG [net.sf.hibernate.impl.SessionImpl] - <transaction completion>
[banking-pilot] 2005-03-04 10:31:56,511 DEBUG [net.sf.hibernate.transaction.JDBCTransaction] - <re-enabling autocommit>
[banking-pilot] 2005-03-04 10:31:56,512 DEBUG [net.sf.hibernate.impl.SessionImpl] - <closing session>
[banking-pilot] 2005-03-04 10:31:56,512 DEBUG [net.sf.hibernate.impl.SessionImpl] - <disconnecting session>
[banking-pilot] 2005-03-04 10:31:56,512 DEBUG [net.sf.hibernate.impl.SessionImpl] - <transaction completion>