-->
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.  [ 6 posts ] 
Author Message
 Post subject: Calling entity manager inside a JPA callback listener
PostPosted: Thu Jan 14, 2016 2:19 pm 
Newbie

Joined: Thu Jan 14, 2016 1:16 pm
Posts: 4
Hello guys,

I'm working in a project based on Spring, JPA/Hibernate and Wicket, I have a use case where I need to listen to some entity A changes in order to do some calculations and update some other entity B in the database, for this purpose I'm using the JPA callback listeners, the problem is I can NOT use the entity manager inside a callback listener, any calls to save or update are ignored...

No matter what I do, I even tried to add CascadeType.ALL on entity A for entity B, and then I changed entity B inside the listener but it is ignored too

I heard I could use a new entity manager to execute the update inside the listener, if this solution is possible how can I get a new entity manager without building a whole entity manager factory ?

Any other suggestions are welcome, thanks in advance :)


-Regards


Top
 Profile  
 
 Post subject: Re: Calling entity manager inside a JPA callback listener
PostPosted: Thu Jan 14, 2016 3:03 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Since you're using Spring, I think you can implement this behavior with Auditing.


Top
 Profile  
 
 Post subject: Re: Calling entity manager inside a JPA callback listener
PostPosted: Thu Jan 14, 2016 5:29 pm 
Newbie

Joined: Thu Jan 14, 2016 1:16 pm
Posts: 4
Thank you mihalcea_vlad, let me look at this Auditing, and I will come back to you later :)


Top
 Profile  
 
 Post subject: Re: Calling entity manager inside a JPA callback listener
PostPosted: Fri Jan 15, 2016 6:40 am 
Newbie

Joined: Thu Jan 14, 2016 1:16 pm
Posts: 4
Hello again,

I was looking at the Spring Data JPA and I realized that it looks similar to Hibernate Envers, and inside the project I found out that they are implementing Hibernate Envers for entities history, so what if Hibernate Envers can solve this situation ? I should better be sticked to it since it is already used in the project, otherwise then I will start to look seriously to Spring Data JPA, what is your opinion ? thanks.


-Regards


Top
 Profile  
 
 Post subject: Re: Calling entity manager inside a JPA callback listener
PostPosted: Fri Jan 15, 2016 7:37 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Envers is more related to Auditing and querying entities. The Spring Data Audit allows you to inject the EntityManager in the entity listeners.
This is the same like when you are using EntityManager for persistence although Spring offers you the EntittyManagerFactory configuration and the transaction management logic.


Top
 Profile  
 
 Post subject: Re: Calling entity manager inside a JPA callback listener
PostPosted: Fri Jan 15, 2016 10:48 am 
Newbie

Joined: Thu Jan 14, 2016 1:16 pm
Posts: 4
Can you please provide additional details? I can't figure out where/how to specify my custom business logic instead of the default one. And at the moment I'm not interesseted to who or when the modification has occured I just need the calculation part.


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