-->
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.  [ 11 posts ] 
Author Message
 Post subject: If Session.reconnect() does nothing, now what???
PostPosted: Thu Oct 20, 2005 2:27 pm 
Regular
Regular

Joined: Tue Mar 01, 2005 2:35 pm
Posts: 60
I'm trying to implement long transactions, but since I can't actually reconnect the session after it's disconnected, I keep getting lazy initialize errors when accessing the object attached to a disconected session. What should I be doing now to implement long transactions? Thanks!

_________________
I always mark helpful posts as such.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 2:31 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
http://hibernate.org/42.html
http://hibernate.org/43.html


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 2:59 pm 
Regular
Regular

Joined: Tue Mar 01, 2005 2:35 pm
Posts: 60
Hmm... that doesn't really help. I'm using the session-per-request pattern for all of my app except one place where I'd like to use a long transaction. All I want to know is how to reconnect a session, not use an entirely new session handling routine that's not going to work for my use case.

_________________
I always mark helpful posts as such.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 3:01 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Uhm, beginning a Transaction obtains a new Connection for the Session from the configured ConnectionProvider, so you'd only have to use reconnect() if you supply a custom Connection object. We un-deprecated it for that purpose in the latest 3.1 again, but that's really the only use case.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 3:27 pm 
Regular
Regular

Joined: Tue Mar 01, 2005 2:35 pm
Posts: 60
Oh, well that's the problem then. I don't start a transaction, I just grab a persistent collection from the object attached to the disconnected session.

_________________
I always mark helpful posts as such.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 4:00 pm 
Regular
Regular

Joined: Tue Mar 01, 2005 2:35 pm
Posts: 60
Check out lines 1233 - 1235 of SessionImpl RC2:

// if ( !jdbcContext.getConnectionManager().isLogicallyConnected() ) {
// reconnect();
// }

_________________
I always mark helpful posts as such.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 4:07 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
I don't really know what you are trying to tell me. If you don't have database transaction you can't have data access.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 4:13 pm 
Regular
Regular

Joined: Tue Mar 01, 2005 2:35 pm
Posts: 60
Well then I must not know how Hibernate handles transactions, but I don't ever start them myself for read-only queries. All I know is that this causes my code to work:

session.reconnect(session.connection());

_________________
I always mark helpful posts as such.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 4:32 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
So you didn't read the two pages I posted earlier?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 4:35 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
My last posting in this thread: You are relying on a side-effect of auto-committed JDBC connections. This is exactly what is mentioned in the Hibernate 3.1 migration guide on the website. In other words, you believe that you can access a database "outside of a transaction" if you only read data. This is of course not true and possible.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 4:38 pm 
Regular
Regular

Joined: Tue Mar 01, 2005 2:35 pm
Posts: 60
Alright. Thanks for your help, Christian.

_________________
I always mark helpful posts as such.


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