-->
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: @PreUpdate is called too often
PostPosted: Tue Apr 28, 2015 5:54 pm 
Regular
Regular

Joined: Fri Dec 17, 2004 10:38 am
Posts: 54
Hi all,

I am using Hibernate 4.3.9 with JPA.

My entity classes
Code:
@Entity
public class User {
   @Id
   @GeneratedValue
   int id;

   int counter;
   String name;

   @PreUpdate
   void preUpdate() {
      counter++;
   }
}

Code:
@Entity
public class Project {
   @Id
   @GeneratedValue
   int id;
}

As you can see the entities are completely unrelated.

Now the persistence code:
Code:
User user = new User();
em.persist(user);
user.setName("name"); // make it dirty

em.createQuery("select p from Project p").getResultList();
em.createQuery("select p from Project p").getResultList();

em.flush();
assertEquals(1, user.getCounter());


I would expect the callback to be called only once - right before the update (on the flush()).
Docs confirm this: https://docs.jboss.org/hibernate/orm/4.0/hem/en-US/html/listeners.html#d0e3013.

But in fact it is called 3 times. Twice on auto flush (althougt the query does not need the User query space!) and once on flush().

Is this an expected behavior or a bug?

Thank you!


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.