-->
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.  [ 2 posts ] 
Author Message
 Post subject: Multiple simultaneous hibernate sessions per thread
PostPosted: Tue Jul 01, 2014 7:32 am 
Newbie

Joined: Tue Jul 01, 2014 7:25 am
Posts: 4
Hi everyone.

I have a question concerning simultaneous sessions and transaction in the same thread using hibernate. I already asked the question on stackoverflow (https://stackoverflow.com/questions/24446629/multiple-simultaneous-hibernate-sessions-per-thread) but I didn't get any answer so I hope you can help me.

I'm working on a REST webservice that uses hibernate as an OR Mapper. I recently upgraded hibernate from 3.2 to 4.3 and got an error because my JTA transaction was rolled back when I wanted to commit it (described here: https://stackoverflow.com/questions/24411519/jtatransaction-localstatus-rolled-back-after-creation). Basically my transaction got rolled back somewhere and then I got an error when I wanted to use that session again (which is correct hibernate behavior).

I think I figured out why I got that error. It is because when I receive the request a long session is started. This session also opens a transaction that will be open for a longer period of time. Besides this long running session/transaction also some small session/transaction should be opened on the same thread. As far as I found out, all sessions get the same UserTransaction to work with and since the small transactions commit and rollback this transaction I run in the error described in my other post.

Since I'm working with a huge code base it is that easy to change the code so that all that side session run in a different thread (in case that would help) or to refactor the whole service so that only one transaction can be open at any time.

Actual Question starts here

Is there any possibility to start multiple simultaneous sessions/transactions in one Thread? If so, what would I have to do, to tell hibernate to do that? If this is not possible what way of accomplishing a similar behavior would you suggest?

Code snippet I use to create the sessions

Code:
Session session = sessionFactory.openSession();
CustomSessionWrapper dpSession = new CustomSessionWrapper(session, this);

if (!session.isClosed() && !session.getTransaction().isActive()) {
    session.beginTransaction();
}

The code worked before I upgraded hibernate so the problem should not be in the CustomSessionWrapper or any other custom class.

Thanks a lot in advance!


Top
 Profile  
 
 Post subject: Re: Multiple simultaneous hibernate sessions per thread
PostPosted: Fri Jul 04, 2014 4:09 am 
Newbie

Joined: Tue Jul 01, 2014 7:25 am
Posts: 4
Does really no one know what the problem might be or if it is even possible to fix this problem?


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