-->
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.  [ 5 posts ] 
Author Message
 Post subject: executeUpdate and Interceptor
PostPosted: Fri May 11, 2007 3:32 pm 
Newbie

Joined: Fri May 11, 2007 3:00 pm
Posts: 3
Hibernate version:3.1

I want to use Query.executeUpdate function to update the records in database and in addition I have to report about each update to another program module through Interceptor.

How can I do this? Maybe exists another interface instead of executeUpdate(), that supports this ability? Or another hibernate trigger mechanism exists?

P.S. solution session.save() or session.update() not respond for my query because I have not Object to pass it as parameter to function save or update but only it's primary key.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 11, 2007 9:26 pm 
Senior
Senior

Joined: Sat Aug 19, 2006 6:31 pm
Posts: 139
I haven't had much success with Interceptors for updates.

Look at Entity Listeners instead (if you use JPA)

http://www.hibernate.org/hib_docs/entit ... #listeners

Or Event listeners if you don't use JPA.

http://www.hibernate.org/hib_docs/v3/re ... ate-events

_________________
Don't forget to rate the reply if it helps..:)

Budyanto


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 12, 2007 5:56 am 
Newbie

Joined: Fri May 11, 2007 3:00 pm
Posts: 3
First of all, thanks for your answer.

I read documentation about Entity Listeners and saw that is not satisfy my request because of "Essentially all of the methods of the Session interface correlate to an event".

But I use the Query interface to run executeUpdate() function. Performing bulk update in this way, I suppouse, will not apply any entity listener.

What I have to do?


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 12, 2007 10:49 am 
Senior
Senior

Joined: Sat Aug 19, 2006 6:31 pm
Posts: 139
Try it....

It works for queries even without going through the session interface. I used the PostLoadEventListener and it works for Query.uniqueResut(). So try the PreUpdateEventListener.

_________________
Don't forget to rate the reply if it helps..:)

Budyanto


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 13, 2007 4:48 pm 
Newbie

Joined: Fri May 11, 2007 3:00 pm
Posts: 3
I test solution with Event listeners and it not work.

Event listener definition (with Spring, but this the same as in hibernate.cfg.xml):

Code:
<property name="eventListeners">
      <map>
      <entry key="post-update">
                      <reflocal="deviceUpdateListener"/></entry>
      </map>
   </property>

   <bean id="updateListener"
      class="cluster.UpdateListener"/>


Class definition:

Code:
public class UpdateListener implements PostUpdateEventListener {
   
   public void onPostUpdate(PostUpdateEvent event) {
               System.out.println("PostUpdateEventListener.onPostUpdate");
        }
}


Code fragment:

Code:

Session s=getHibernateTemplate().
                    getSessionFactory().getCurrentSession();
Query q=s.createQuery("update versioned User w set                                                              w.userName=:name");
q.setString("name", "Alex");
q.executeUpdate();


This didn't affect event listener. But use session.update() affect event listener with the same configuration.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.