-->
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: Multiple Sessions in a single thread?
PostPosted: Mon Oct 27, 2003 12:12 pm 
Newbie

Joined: Wed Oct 15, 2003 4:31 pm
Posts: 17
Howdy,

I'm writting some generic service routines that need access to the database via hibernate and need to make changes via a transaction independent of any other Hibernate associated sessions/transactions.

I'm finding that in my "second" (that is, in creation order within the same thread) session, I can make a change to the database by manipulating my object and committing the transaction (note: all instances were fetched from get/load/find local to the session I'm using - object usage isn't crossing session instances/associations).

The change is fine, the save() and commit are find but when I close this second session, hibernate throws a very odd exception:

10:35:40,564 DEBUG BatcherImpl:245 - closing statement
10:35:40,565 DEBUG SessionImpl:2676 - post flush
10:35:40,586 DEBUG SessionImpl:506 - transaction completion
10:35:40,587 DEBUG SessionImpl:494 - closing session
10:35:40,588 DEBUG SessionImpl:3269 - disconnecting session
10:35:40,594 DEBUG JDBCExceptionReporter:18 - SQL Warning
java.sql.SQLWarning: WARNING: ROLLBACK: no transaction in progress

at org.postgresql.jdbc1.AbstractJdbc1Connection.addWarning(AbstractJdbc1Connection.java:430)
at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:111)
at org.postgresql.jdbc1.AbstractJdbc1Connection.ExecSQL(AbstractJdbc1Connection.java:482)
at org.postgresql.jdbc1.AbstractJdbc1Connection.ExecSQL(AbstractJdbc1Connection.java:461)
at org.postgresql.jdbc1.AbstractJdbc1Connection.rollback(AbstractJdbc1Connection.java:1031)
at com.mchange.v2.c3p0.impl.C3P0PooledConnection.reset(C3P0PooledConnection.java:251)
at com.mchange.v2.c3p0.impl.C3P0PooledConnection.access$000(C3P0PooledConnection.java:35)
at com.mchange.v2.c3p0.impl.C3P0PooledConnection$ProxyConnectionInvocationHandler.doSilentClose(C3P0PooledConnection.java:531)
at com.mchange.v2.c3p0.impl.C3P0PooledConnection$ProxyConnectionInvocationHandler.invoke(C3P0PooledConnection.java:636)
at com.mchange.v2.c3p0.impl.$Proxy0.close(Unknown Source)
at net.sf.hibernate.connection.C3P0ConnectionProvider.closeConnection(C3P0ConnectionProvider.java:48)

at org.postgresql.jdbc1.AbstractJdbc1Connection.addWarning(AbstractJdbc1Connection.java:430)
at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:111)
at org.postgresql.jdbc1.AbstractJdbc1Connection.ExecSQL(AbstractJdbc1Connection.java:482)
at org.postgresql.jdbc1.AbstractJdbc1Connection.ExecSQL(AbstractJdbc1Connection.java:461)
at org.postgresql.jdbc1.AbstractJdbc1Connection.rollback(AbstractJdbc1Connection.java:1031)
at com.mchange.v2.c3p0.impl.C3P0PooledConnection.reset(C3P0PooledConnection.java:251)
at com.mchange.v2.c3p0.impl.C3P0PooledConnection.access$000(C3P0PooledConnection.java:35)
at com.mchange.v2.c3p0.impl.C3P0PooledConnection$ProxyConnectionInvocationHandler.doSilentClose(C3P0PooledConnection.java:531)
at com.mchange.v2.c3p0.impl.C3P0PooledConnection$ProxyConnectionInvocationHandler.invoke(C3P0PooledConnection.java:636)
at com.mchange.v2.c3p0.impl.$Proxy0.close(Unknown Source)
at net.sf.hibernate.connection.C3P0ConnectionProvider.closeConnection(C3P0ConnectionProvider.java:48)
at net.sf.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:78)
at net.sf.hibernate.cfg.Configuration.buildSettings(Configuration.java:963)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:658)
at SOpen.spm.util.SPMSessionContext.initializeAppSessionContext(SPMSessionContext.java:22)
at local.gerry.TestBase.initializeApp(TestBase.java:35)
at local.gerry.TestBase.doTest(TestBase.java:65)
at local.gerry.TestBase.main(TestBase.java:111)
10:35:40,598 WARN JDBCExceptionReporter:20 - SQL Warning: 0, SQLState: null
10:35:40,598 WARN JDBCExceptionReporter:28 - WARNING: ROLLBACK: no transaction in progress

10:35:40,601 DEBUG SessionImpl:506 - transaction completion

The odd things are

1) I'm not attempting to roll back any transaction when this occurs
2) There are no other unhandled exceptions in progress when this happens
3) The main thread of execution (actually, because this is a test program ,the ONLY thread of execution) is not in the initializeApp() call at all (that had happened much earlier in execution).
4) The exception handler wrapped around the close() call is never invoked. That code looks like:

} finally {
if (theSession != null) {
try {
theSession.close();
} catch (Exception closeError) {
AppSessionContext.getDefaultLogger().error("Unable to close unmanaged exception while SETTING exportable translation value", closeError);
}

theSession = null;
}
}


Oddly, the changes I make have made it back to the database, but any access to the same object (by same, I mean same ID, not same instance) via my original session return the old value. I suspect that the exception is messing up a cache entry somewhere (??)

I'm not really sure where to start with this one. I guess asking if it's OK to have more than one session per thread would be a good place.

I have confirmed (via println() and stepping via a debugger) that the root of the reported exception is not where the code is executing when the close() call is invoked and that for this test, there is only a single thread running.

Any ideas where to start figuring this one out?

Thanks!

Gerry


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 27, 2003 5:22 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
The error is indication that the operation was not under the influence of a transaction. Also, once an exception is throw the session should not be used any longer as it can be in an invalid state. Alternatively, call sess.evict() which clears that cache.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 27, 2003 5:35 pm 
Newbie

Joined: Wed Oct 15, 2003 4:31 pm
Posts: 17
david wrote:
The error is indication that the operation was not under the influence of a transaction. Also, once an exception is throw the session should not be used any longer as it can be in an invalid state. Alternatively, call sess.evict() which clears that cache.


See, that's the wierd part - the claimed area it was running in wasn't in fact where the thread was. I steppped through with a debugger and got al the way to the .close() call. When I stepped over that, (very, very far away from the code identified in the root of the exception), this was the stack trace that came out.

After the transaction was comitted (which it did without error) there are no other references to the session (other than closing it) or the transaction.

Also, after that exception is thrown, there are no other references to the session (even if the close() didn't throw an exception, there would be no additional references to that session.

I don't understand how the exception can identify a section of code that only executes once in the program and even then, execute long before this method (hubreds and hunreds of lines earlier). It's not like this is multi-threaded (confirmed - there are no other threads -- just the main thread -- wehen the exception happens).

I wonder if this is possible a hibernate/c3p0 problems - I am using hiber 2.1beta4.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 27, 2003 5:40 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Try disabling batch updates.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 27, 2003 5:45 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
That is not an exception being thrown. A JDBC warning is being logged. Thats all.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 24, 2004 10:25 am 
Newbie

Joined: Fri May 07, 2004 6:05 am
Posts: 17
I happen to have exactly the same problem, with Hibernate 2.1.3 and c3p0 0.8.4.5

All I can add to the original post is that everything works fine when I disable c3p0 pooling

In my case, I do not make any change to the record, it's just a loading procedure, so the object returned by the mapping is always correct.

It's just that I don't like to have warnings throwed when I don't understand why

I insist, this is no exception, so is it dangerous in any way to let the program continue, and is there a safety problem if I do, or is it better to stop it - which in my case would mean stop using the connection pooling


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 24, 2004 11:10 am 
Newbie

Joined: Fri May 07, 2004 6:05 am
Posts: 17
To be more precise, I use postgreSQL 7.3


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 25, 2004 8:34 am 
Newbie

Joined: Fri May 07, 2004 6:05 am
Posts: 17
One more precision :

I build a test case, on a test project, with a very simplified mapping, and I can reproduce this problem. It has nothing in common with the other project I was talking from earlier, except it uses the same DB, and c3p0.

What is more revelant, is that sometimes it works and sometimes not.

The first time I launch this class, everything works fine, the warning is not launched. Then if I relaunch it as soon as it ends, the exception is launched. But when I wait a few seconds (typically 2 or 3), it is not launched.


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.