-->
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.  [ 4 posts ] 
Author Message
 Post subject: Transaction commit - db connection lost
PostPosted: Fri Mar 18, 2016 12:34 pm 
Newbie

Joined: Fri Mar 18, 2016 12:07 pm
Posts: 2
Hi guys,

I am upgrading my application from hibernate 4.2.18 to 5.1.0. I am using current session from session factory for repeated execution in single thread. I was used to that when connection to database is lost, commit on transaction remove session from threadlocal. How to achieve similar behavior in 5.1.0. version? Because now I am obtaining same session in case of that connection to database is lost.

Code:
        val session = sessionFactory.currentSession
        var transaction: Transaction? = null
        try {
            transaction = session.beginTransaction()
            // do something with session
            transaction!!.commit()
        } catch (e: Exception) {
            transaction?.rollback()
            throw e
        }


Top
 Profile  
 
 Post subject: Re: Transaction commit - db connection lost
PostPosted: Sat Mar 19, 2016 3:53 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
If the connection is lost, only the DataSource could allow you to restablish it. But in that case the transaction is lost because the transaction is bound to the underlying connection anyway.


Top
 Profile  
 
 Post subject: Re: Transaction commit - db connection lost
PostPosted: Sat Mar 19, 2016 9:17 am 
Newbie

Joined: Fri Mar 18, 2016 12:07 pm
Posts: 2
I know that transaction is lost. In previous versions I can reuse the same thread because transaction.commit() was removing broken session from session map in ThreadLocalSessionContext in case of connection lost during commit so that next run in same thread obtained new session. Now the broken session remains in session map in ThreadLocalSessionContext. Do I have to remove (close) it explicitly or is sufficient to use new thread and session map in ThreadLocalSessionContext is cleared in background when no longer user.


Top
 Profile  
 
 Post subject: Re: Transaction commit - db connection lost
PostPosted: Mon Mar 21, 2016 1:55 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
I think it's better to explicitly close the Session when you get an exception. If the Session is not removed from the TLSC, then it must be an issue.


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