Hello,
I'm having a strange behavior trying to use this feature: I've a entity which has a method annotated by @PrePersist and @PreUpdate. When I call my entityManager.persist, the callback gets fired, but when I call entityManager.merge it does not, even changing the entity content.
As an alternative to annotated methods at the entity class, I can use orm.xml to specify entity listeners for my Entity. Doing that, I still can't get my callback method fired by calling entityManager.merge (for persist, it works fine), however, when calling entityManager.flush just after merge then it gets fired (but still the flush call does not work using @PreUpdate).
Finally, I'm still able to specify a "default" event listener on my orm.xml (which is not what I want, since I only need it to one particular entity) then it works the way I think it's supposed to work, that means firing the callback method after calling merge and persist (whithout the need to call entityManager.flush).
Here is the code to represent the cenario:
List<Person> list = em.createQuery("select p from Person p where id = 2").getResultList(); Person p = list.get(0); p.setEmail(null); em.merge(p); //I think the calllback should be fired here!
The orm.xml
<entity class="br.com.mydomain.Person"> <entity-listeners> <entity-listener class="br.com.mydomain.PersonEventListener" /> </entity-listeners> </entity>
The orm.xml with default listener (the only way the thing works!) <persistence-unit-metadata> <persistence-unit-defaults> <entity-listeners> <entity-listener class="br.com.mydomain.PersonEventListener"/> </entity-listeners> </persistence-unit-defaults> </persistence-unit-metadata> </entity-mappings>
I'm using Hibernte 3.4.0.ga
Is anyone aware of a solution?
Is there an patch for this version that corrects the bug? I searched at the maven repo and couldn't find it..
Thanks in advance!
|