I am trying using Hibernate events instead of interceptor but I am unable to update or save the entity in FlushEntityEventListener
Please advise, I have tried with SaveOrUpdateEventListener which works fine but it get called twice when I call SaveOrUpdate method and after session flush
Is it possible to update properties in FlushEntityEventListener and get saved in database ???
Hibernate 3.2.0.cr1, with spring 2.0-rc3
Code:
public class FlushEntityEventListenerImpl implements FlushEntityEventListener {
private static final long serialVersionUID = -8419747551835823564L;
private Log log = LogFactory.getLog(getClass());
/* (non-Javadoc)
* @see org.hibernate.event.FlushEntityEventListener#onFlushEntity(org.hibernate.event.FlushEntityEvent)
*/
public void onFlushEntity(FlushEntityEvent event) throws HibernateException {
log.debug("Custom FlushEntityEventListenerImpl is called....");
if (event.getEntity() instanceof AbstractDomainObject) {
final Object entity = event.getEntity();
AbstractDomainObject ado = (AbstractDomainObject) entity;
String who = "testUser";
Timestamp when = new Timestamp(System.currentTimeMillis());
ado.setModifiedBy(who);
ado.setModifiedDate(when);
}
}
spring context in sessionFactory
Code:
<property name="eventListeners">
<map>
<entry key="flush-entity">
<list>
<bean class="com.liquid.ingest.domain.FlushEntityEventListenerImpl"/>
<bean class="org.hibernate.event.def.DefaultFlushEntityEventListener"/>
</list>
</entry>
</map>
</property>