-->
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.  [ 1 post ] 
Author Message
 Post subject: Seeking a way to fire an event on a query akin to LoadEvent
PostPosted: Sat Feb 02, 2008 6:24 pm 
Newbie

Joined: Sat Feb 02, 2008 6:10 pm
Posts: 1
Is there a way to use the Hibernate event architecture to fire an event when an object is fetched using a query, the same way a LoadEvent is fired when an object is loaded?

I am using hibernate 3.2.5.ga and hibernate-annotations 3.3.0.ga with Spring 2.0.2. I have this in my sessionFactory definition:
Code:
<bean id="sessionFactory"      class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
...
        <property name="eventListeners">
           <map>
              <entry>
               <key><value>load</value></key>
               <list>
                  <ref bean="defaultHibernateLoadEventListener" />
                  <ref bean="serviceInjectingLoadEventListener" />
               </list>               
            </entry>
           </map>
        </property>
</bean>

And the serviceInjectingLoadEventListener executes as expected every time I do a Session.load:
Code:
public SomeEntity loadSomeEntity(Serializable id) {
      Session session = SessionFactoryUtils.getSession(this.getSessionFactory(), true);
      return (SomeEntity) session.load(SomeEntity.class, id);      
   }


But I would also like to execute the same listener during a query, like this:
Code:
   public SomeEntity findSomeEntityBySomeProperty(String someProperty) {
      Session session = SessionFactoryUtils.getSession(this.getSessionFactory(), true);
      Criteria crit = session.createCriteria(SomeEntity.class);
      crit.add(Restrictions.eq("someProperty", someProperty));
      List list = crit.list();
      return (SomeEntity) CollectionUtils.findOne(list);      
   }


Is there a good way to do this?


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

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.