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!