-->
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: Entity not saving in FlushEntityEventListener
PostPosted: Thu Oct 12, 2006 1:48 pm 
Newbie

Joined: Tue Dec 13, 2005 6:47 pm
Posts: 7
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>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 13, 2006 4:14 am 
Beginner
Beginner

Joined: Fri Oct 28, 2005 7:11 am
Posts: 20
Nope. You are not allowed to modify on object in Flush event (as the Hibernate Team told me some time ago). IMO there should be event for such purpose (to easily implement 'user'/audit data).


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.