-->
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: Entity LifeCycle Callbacks
PostPosted: Tue Oct 18, 2011 9:25 am 
Newbie

Joined: Tue Oct 18, 2011 8:47 am
Posts: 1
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!


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.