Hi,
I have been using Hibernate with Spring without any issues for sometime now. This is a remarkable product and it truly is an endowment to Software development. However, to get to the point, I recently started a new project and a suggestion was made to write Data Access layers that conform to JPA standards. Now luckily for me, Hibernate had also decided to implement the JPA spec, which meant that apart from some minor modifications to the DAO objects and the Spring configuration file, everything else pretty much stayed the same. However, I have been struggling with a hibernate feature, the Interceptor, which I have used a lot previously and has worked without any issues. But ever since, I moved to the JPA based implementation of the product I have not been able to persist the changes made to entities within an interceptor, and this works fine with the pure Hibernate based implementation. So basically, here is an example of onFlushDirty() that works with pure Hibernate but not with a Hibernate+JPA configuration.
public boolean onFlushDirty(Object entity, Serializable id,
Object[] currentState, Object[] previousState,
String[] propertyNames, Type[] types) throws CallbackException {
if(entity instanceof Order){
Orders order = (Orders)entity;
TradingEventLog orderTradingEvent = order.createTradingEvent();
for ( int i=0; i<propertyNames.length; i++ ) {
if ( "tradingDeskShortName".equals( propertyNames[i] ) ) {
TradingAuditLog audit = orderTradingEvent.createTradingAudit();
audit.setAuditLogTmstmp(new Date());
audit.setAuditLogTypCd("T");
audit.setOtherValue(propertyNames[i]);
audit.setOldValue(previousState[i].toString());
audit.setNewValue(currentState[i].toString());
audit.getAuditInfo().setLastUpdateTime(new Date());
audit.getAuditInfo().setLastUpdateUser(user);
}
if ( "tradingEvents".equals( propertyNames[i] )) {
currentState[i] = order.getTradingEvents();
return true;
}
}
return false;
}
The changes made to currentState are not being persisted to the database for some reason. As I said, this works fine with just Hibernate. In my persistence.xml file I am setting the property hibernate.ejb.interceptor to my implementation of an interceptor and the interceptor code is invoked as well, as I am able to debug into this code. But for some reason the changes are not being persisted. Is there some JPA specific configuration that I am forgetting or not setting correctly? Can someone tell me what needs to happen for the above example to work correctly with a Hibernate+JPA based implementation via Spring.
|