You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Chas douglass <ch...@gmail.com> on 2005/10/30 15:46:47 UTC

Invalid SQL State

I'm using Derby embedded 10.1.1.0 with Hibernate 3.0.5.  I have one thread
running, iterating through a number of transactions.  A second thread starts up,
performs 0 or more transactions, and then ends.  At this point, thread 1 gets:

06:34:05,431  WARN JDBCExceptionReporter:71 - SQL Error: 20000, SQLState: 25000
06:34:05,431 ERROR JDBCExceptionReporter:72 - Invalid transaction state.
org.hibernate.exception.GenericJDBCException: Cannot close connection

I get no errors unless the two threads overlap.

Can anyone provide any insight into what this error is trying to tell me?  Or,
perhaps, suggest what further information would be necessary?

Thanks.

Chas Douglass



Re: Invalid SQL State

Posted by Chas douglass <ch...@gmail.com>.
Michael J. Segel <ms...@...> writes:

> 
> On Sunday 30 October 2005 08:46, Chas douglass wrote:
> > I'm using Derby embedded 10.1.1.0 with Hibernate 3.0.5.  I have one thread
> > running, iterating through a number of transactions.  A second thread
> > starts up, performs 0 or more transactions, and then ends.  At this point,
> > thread 1 gets:
> >
> > 06:34:05,431  WARN JDBCExceptionReporter:71 - SQL Error: 20000, SQLState:
> > 25000 06:34:05,431 ERROR JDBCExceptionReporter:72 - Invalid transaction
> > state. org.hibernate.exception.GenericJDBCException: Cannot close
> > connection
> >
> > I get no errors unless the two threads overlap.
> >
> > Can anyone provide any insight into what this error is trying to tell me? 
> > Or, perhaps, suggest what further information would be necessary?
> >
> > Thanks.
> >
> > Chas Douglass
> Your  code isn't thread safe?
> 

Um... thanks.

All of my db access is through Hibernate, and I'm using the ThreadLocal Session
Factory pattern.

Briefly, that means that each thread grabs a new Hibernate Session instance when
it starts, uses that session instance for 0-n transactions, and then closes that
session just before exiting.

Hibernate claims their Session to be thread safe.

What I was hoping for was some more explanation of what "Invalid SQL State"
meant to help me track it down.

Years ago (and I mean YEARS ago) I was working on a Basic interpreter and we
almost included an error "SOMETHING WRONG WITH PROGRAM".  At least we understood
it was a joke.

Chas Douglass





Re: Invalid SQL State

Posted by "Michael J. Segel" <ms...@segel.com>.
On Sunday 30 October 2005 08:46, Chas douglass wrote:
> I'm using Derby embedded 10.1.1.0 with Hibernate 3.0.5.  I have one thread
> running, iterating through a number of transactions.  A second thread
> starts up, performs 0 or more transactions, and then ends.  At this point,
> thread 1 gets:
>
> 06:34:05,431  WARN JDBCExceptionReporter:71 - SQL Error: 20000, SQLState:
> 25000 06:34:05,431 ERROR JDBCExceptionReporter:72 - Invalid transaction
> state. org.hibernate.exception.GenericJDBCException: Cannot close
> connection
>
> I get no errors unless the two threads overlap.
>
> Can anyone provide any insight into what this error is trying to tell me? 
> Or, perhaps, suggest what further information would be necessary?
>
> Thanks.
>
> Chas Douglass
Your  code isn't thread safe?

-- 
Michael Segel
Principal
MSCC
(312) 952-8175

Re: Invalid SQL State

Posted by Rick Hillegas <Ri...@Sun.COM>.
Hi Chas,

Derby raises an exception with the text "Invalid transaction state". 
However, that message has a different sql state (x0x03) than the one 
you're seeing. Here's the blurb from the Derby code describing what 
makes Derby raise this exception:

        // find if there are any held cursors from previous isolation level.
        // if yes, then throw an exception that isolation change not 
allowed until
        // the held cursors are closed.
        // I had to move this check outside of transaction idle check 
because if a
        // transactions creates held cursors and commits the 
transaction, then
        // there still would be held cursors but the transaction state 
would be idle.
        // In order to check the above mentioned case, the held cursor check
        // shouldn't rely on transaction state.

You might want to look at derby.log to see if there's a stack trace and 
then forward that stack trace to this list. That could help us push this 
forward.

Regards,
-Rick

Chas douglass wrote:

>I'm using Derby embedded 10.1.1.0 with Hibernate 3.0.5.  I have one thread
>running, iterating through a number of transactions.  A second thread starts up,
>performs 0 or more transactions, and then ends.  At this point, thread 1 gets:
>
>06:34:05,431  WARN JDBCExceptionReporter:71 - SQL Error: 20000, SQLState: 25000
>06:34:05,431 ERROR JDBCExceptionReporter:72 - Invalid transaction state.
>org.hibernate.exception.GenericJDBCException: Cannot close connection
>
>I get no errors unless the two threads overlap.
>
>Can anyone provide any insight into what this error is trying to tell me?  Or,
>perhaps, suggest what further information would be necessary?
>
>Thanks.
>
>Chas Douglass
>
>
>  
>


Re: Invalid SQL State

Posted by Dy...@Sun.COM.
Chas douglass <ch...@gmail.com> writes:

> I'm using Derby embedded 10.1.1.0 with Hibernate 3.0.5.  I have one thread
> running, iterating through a number of transactions.  A second thread starts up,
> performs 0 or more transactions, and then ends.  At this point, thread 1 gets:
>
> 06:34:05,431  WARN JDBCExceptionReporter:71 - SQL Error: 20000, SQLState: 25000
> 06:34:05,431 ERROR JDBCExceptionReporter:72 - Invalid transaction state.
> org.hibernate.exception.GenericJDBCException: Cannot close connection
>
> I get no errors unless the two threads overlap.
>
> Can anyone provide any insight into what this error is trying to tell me?  Or,
> perhaps, suggest what further information would be necessary?

Do you by any chance, try to close a connection while you have an open
transaction? Have you tried inserting a c.rollback() or c.commit()
before closing the connction?

Are the two threads sharing the same connection? If they do, I think
you need block access from other threads to the connection object
while you have an open transaction. If you can, you should really try
to give each thread their own connection. That will make things much
simpler.

I don't know how much of this is actually under your control when using
Hibernate, though...

HTH
-- 
dt