-->
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.  [ 8 posts ] 
Author Message
 Post subject: Possible breakage from 3.1 to 3.1.3
PostPosted: Wed Jun 07, 2006 9:28 am 
Newbie

Joined: Sun May 28, 2006 9:43 am
Posts: 6
Hi,

As you can see below this very simple program causes a stack overflow. If I comment out the .connection() and reconnect() lines there is no problem. This code used to work in 3.1.

Any help would be greatly appreciated.

Thanks,
Yair

Hibernate version: 3.1.3

Mapping documents: test with error doesn't have any mapping

Code between sessionFactory.openSession() and session.close():

Connection conn = session.connection();
session.reconnect(conn);


Full stack trace of any exception that occurs:

java.lang.StackOverflowError
at java.lang.reflect.InvocationTargetException.<init>(InvocationTargetException.java:54)
at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.hibernate.jdbc.BorrowedConnectionProxy.invoke(BorrowedConnectionProxy.java:40)
at $Proxy0.isClosed(Unknown Source)
at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.hibernate.jdbc.BorrowedConnectionProxy.invoke(BorrowedConnectionProxy.java:40)
at $Proxy0.isClosed(Unknown Source)
at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.hibernate.jdbc.BorrowedConnectionProxy.invoke(BorrowedConnectionProxy.java:40)
at $Proxy0.isClosed(Unknown Source)
...

Name and version of the database you are using:
Oracle 10g

The generated SQL (show_sql=true):

No SQL is generated


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 07, 2006 8:24 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Can you reconnect a session that hasn't been disconnected? Try this, instead:
Code:
Connection conn = session.close();
session.reconnect(conn);

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 11, 2006 8:10 am 
Newbie

Joined: Sun May 28, 2006 9:43 am
Posts: 6
Well the code itself works, but it is not what I am after. I want to "take" the connection from the session and then reconnect it and keep working with the session. I use this in my code to run a "set transaction read only" statement on the connection, thus making the session see a read only view of the database. Another use is to insert rows into the database not through Hibernate, but using the session object's connection.

Thanks,
Yair


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 11, 2006 7:36 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Why do you need to reconnect in that situation? Can't you just use the connection returned from connection()?

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 12, 2006 3:56 am 
Newbie

Joined: Sun May 28, 2006 9:43 am
Posts: 6
Well, if I don't reconnect, then the connection will not be closed when I use session.close() and will leak. Is this not the case?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 12, 2006 5:44 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
That's not the case.

If you're using Hibernate-supplied connections, it's your responsibility to close the connection (after you're done with it and after you close the hibernate session). At no point are you supposed to reconnect the connection.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 13, 2006 2:03 am 
Newbie

Joined: Sun May 28, 2006 9:43 am
Posts: 6
So what you are saying is that if the connection comes from Hibernate (e.g. using c3p0 as the backend connection pool), and I use the session.connection() call, the only way that this connection is returned to the pool is if I call connection.close() myself?

Also, if I use the connection() call, and subsequently continue to use the session object, will it continue to use the same connection or acquire a new one? I would like it to use the same connection, so that I can call "set transaction read only" on it and then use Hibernate for the rest of my DB access.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 13, 2006 2:28 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
1) Only if you're using aggressive connection release, but I believe that c3p0 does. You should verify this.

2) Yes, hibernate will continue to use the same connection, so don't close the connection until after you close the session.

_________________
Code tags are your friend. Know them and use them.


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