-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: hibernate.ejb.interceptor
PostPosted: Mon Sep 10, 2007 3:12 pm 
Newbie

Joined: Mon Sep 10, 2007 3:09 pm
Posts: 1
Location: boston
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.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 14, 2007 1:57 am 
Newbie

Joined: Mon Aug 27, 2007 2:43 am
Posts: 8
One buddy to another.

Nasim, do a getJpaTemplate().flush(); after getJpaTemplate().merge(detachedInstance); from the DAO where you update the order.

It works!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.