-->
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.  [ 7 posts ] 
Author Message
 Post subject: What am i allowed to to during hibernate callback?
PostPosted: Thu May 15, 2008 3:46 am 
Beginner
Beginner

Joined: Mon Apr 07, 2008 12:49 pm
Posts: 33
Hey,

I understand that the entity manager is in fagile state,during hibernate callback, so you are not allowed to do some things.

I need to run some queried during pre-remove callback.
The queries need to be based on the current context. they need to check some condition?

Is it ok to do this?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 15, 2008 4:39 am 
Newbie

Joined: Fri Jul 07, 2006 6:20 am
Posts: 4
did you try doing that??? were u successful?


Top
 Profile  
 
 Post subject: I did it
PostPosted: Thu May 15, 2008 4:42 am 
Beginner
Beginner

Joined: Mon Apr 07, 2008 12:49 pm
Posts: 33
it wotk, but in some other scenario (more complicated) it didnt work.
another issue with this is when the callback call from cascade.


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 25, 2008 7:56 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 8:07 pm
Posts: 229
Location: Brisbane, Australia
I asked a similar sort of question in this topic: http://forums.hibernate.org/viewtopic.php?t=986784

The book basically says you can't use the EM during a callback, by definition of the standard.
The same restriction exists for the traditional Hibernate Session, but the workaround is pretty easy.

As, you can see from the topic though - I've no idea how to create a new EntityManager on the same connection. At the moment, my workaround is just to drop back to using a brand new Hibernate Session. It's a bit dodgy though, swapping from JPA API and back to the Hibernate API just because I can't figure out how to create an EM.

_________________
Cheers,
Shorn.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 10, 2008 9:36 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Indeed, interacting with the existing entity manager during a callback isn't allowed. A new session would just create a new connection, which is separate from the callback, and may have its own callback.

-Cameron

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 10, 2008 11:22 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 8:07 pm
Posts: 229
Location: Brisbane, Australia
Cameron McKenzie wrote:
A new session would just create a new connection, which is separate from the callback, and may have its own callback.


That's the trick, you don't let the new session create a new JDBC connection, you create a new session wrapped around the old connection from the original session. Works fine, I've just gotta figure out how to do it with an EnitityManager instead of a HB Session.

_________________
Cheers,
Shorn.


Top
 Profile  
 
 Post subject: Can you
PostPosted: Sun Jun 15, 2008 12:44 am 
Beginner
Beginner

Joined: Mon Apr 07, 2008 12:49 pm
Posts: 33
Thanks for your answer.
Can you please show how you did it with EM. i work in J2ee mode (with jboss4.2).

Any way it will not solve my problem, because i need to for each entity that are going to be deleted to execute query against the DB, but if you are in another EM than the result might not be as you expected since the first EM didnt execute flush and during cascade you cannot call to flush.

Thank you


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