-->
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.  [ 10 posts ] 
Author Message
 Post subject: Error while using hibernate-4.0.1
PostPosted: Wed Mar 07, 2012 12:13 pm 
Newbie

Joined: Wed Mar 07, 2012 10:04 am
Posts: 2
We wish to switch from Hibernate 3.0 to Hibernate 4.0.1

The application is working very well with Hibernate 3.0 but following exception is thrown while using 4.0.1

[07 Mar 2012 09:23:45,062] [ERROR] [main ].closeSession() GenericDAOImpl - Exception occurred while closing hibernate session.
org.hibernate.HibernateException: proxy handle is no longer valid
at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.errorIfInvalid(AbstractProxyHandler.java:63)
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:100)
at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
at $Proxy2.getWrappedObject(Unknown Source)
at org.hibernate.engine.jdbc.internal.JdbcResourceRegistryImpl.close(JdbcResourceRegistryImpl.java:256)
at org.hibernate.engine.jdbc.internal.JdbcResourceRegistryImpl.cleanup(JdbcResourceRegistryImpl.java:182)
at org.hibernate.engine.jdbc.internal.JdbcResourceRegistryImpl.close(JdbcResourceRegistryImpl.java:247)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.close(LogicalConnectionImpl.java:197)
at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.close(JdbcCoordinatorImpl.java:141)
at org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl.close(TransactionCoordinatorImpl.java:274)
at org.hibernate.internal.SessionImpl.close(SessionImpl.java:275)
at com.ibm.wdp.bsscfw.dataservice.dao.GenericDAOImpl.closeSession(GenericDAOImpl.java:813)


Due to this error no DB connections is closed. Hence the application is running out of connections immediately. The database used in the app is DB2 9.7 and the drivers used are also from db2 9.7 installation. I also tried using old drivers but same error is thrown for old drivers as well

I request all to help in resolving this issue.

Thanks,
Krishnaprasad

_________________
Regards,
Krishnaprasad (KP)


Top
 Profile  
 
 Post subject: Re: Error while using hibernate-4.0.1
PostPosted: Mon Mar 12, 2012 4:02 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Hm, which connection-pool (or Datasource) implementation are you using ?


Top
 Profile  
 
 Post subject: Re: Error while using hibernate-4.0.1
PostPosted: Mon Mar 12, 2012 5:43 am 
Newbie

Joined: Wed Mar 07, 2012 10:04 am
Posts: 2
we are using c3p0 datasources/connection pooling. Following are the property values in the hibrnate.cfg.xml

<property name="hibernate.connection.isolation">2</property>
<property name="hibernate.c3p0.acquire_increment">5</property>
<property name="hibernate.c3p0.idle_test_period">120</property>
<property name="hibernate.c3p0.min_size">3</property>
<property name="hibernate.c3p0.max_size">%$%DB_MAXCONNECTIONS$</property>
<property name="hibernate.c3p0.max_statements">0</property>
<property name="hibernate.c3p0.timeout">120</property>

The jar file used is c3p0-0.9.1.jar

_________________
Regards,
Krishnaprasad (KP)


Top
 Profile  
 
 Post subject: Re: Error while using hibernate-4.0.1
PostPosted: Mon Mar 12, 2012 6:30 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Hi,

when closing a connection, hibernate first closes are related jdbc-statements which were issued through this connection.
During this process hibernate detects that a jdbc-statements is already invalidated.
This in theory should only occur on inappropriate concurrent access to a session out from different java threads.
Looks like that
com.ibm.wdp.bsscfw.dataservice.dao.GenericDAOImpl.closeSession
is called contemporaneously out from 2 threads on the same hiberenate session, can that be?


Top
 Profile  
 
 Post subject: Re: Error while using hibernate-4.0.1
PostPosted: Mon Mar 12, 2012 12:39 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
I'm just hitting the same issue, I'm just starting to dig but I hit the exception which lead me to this thread.

Using c3p0 as well, I'm leaning towards it being wrapped up in the sessions where I piggy back off the session's current connection to do some extra work but I'm not sure yet.

_________________
Some people are like Slinkies - not really good for anything, but you still can't help but smile when you see one tumble down the stairs.


Top
 Profile  
 
 Post subject: Re: Error while using hibernate-4.0.1
PostPosted: Mon Mar 12, 2012 1:46 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
I have confirmed that the only time I'm getting this is when I use session.withSessionOptions().connection().openSession(), the spawned session closes fine but when it goes to close the main session it blows in the LogicalConnectionImpl.close() method and doesn't get into the release connection block.

_________________
Some people are like Slinkies - not really good for anything, but you still can't help but smile when you see one tumble down the stairs.


Top
 Profile  
 
 Post subject: Re: Error while using hibernate-4.0.1
PostPosted: Mon Mar 12, 2012 3:06 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
It looks like the same statement is getting registered with 2 different statement xrefs. When the close is called on the statement it's being invalidated but then only removed from one. Then when the session cleanup executes it encouters the invalid statements and blows the exception, still digging.

_________________
Some people are like Slinkies - not really good for anything, but you still can't help but smile when you see one tumble down the stairs.


Top
 Profile  
 
 Post subject: Re: Error while using hibernate-4.0.1
PostPosted: Mon Mar 12, 2012 7:43 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
Ok, after playing with this for the better part of the day and stripping it down it looks like it has something to do with the ConnectionProxyHandler

It looks like when you do something like session.sessionWithOptions().connnection() you get a proxy 2 levels deep and then when the register(Statement statement) gets called the same instance of the statement ends up in 2 layers of xref maps from the JdbcResourceRegistry. When the first session closes then it invalidates the statement and then when the overall session tries to close it fails and blows out before releasing the connection and leaking it.

Here's an arbitrary snippet of code that will cause the behavior, it's 3 levels deep since I wanted to get my head wrapped around whether or not the register would be called 3 times or not (it was).

The exception that it blows gets eaten and leaks the connection, it looks like it's already been raised as a JIRA https://hibernate.onjira.com/browse/HHH-7020
I'll go and throw my 2c in.

Code:
        //replace this with however you obtain a session
        Session session = obtainSession();
        Transaction t = session.beginTransaction();
       
        Session secondSession = session.sessionWithOptions().connection().openSession();
       
        Session thirdSession = secondSession.sessionWithOptions().connection().openSession();
       
        SQLQuery sqlQuery = thirdSession.createSQLQuery("select 1 from dual");
        sqlQuery.list();
        thirdSession.close();
        secondSession.close();
        t.commit();
        session.close();

_________________
Some people are like Slinkies - not really good for anything, but you still can't help but smile when you see one tumble down the stairs.


Top
 Profile  
 
 Post subject: Re: Error while using hibernate-4.0.1
PostPosted: Mon Mar 12, 2012 11:27 pm 
Newbie

Joined: Mon Mar 12, 2012 11:18 pm
Posts: 2
While reading your post it seems that you research on this topic very much. I must tell you that your information is very informative and it helps other also.

_________________
None is of freedom or of life deserving unless he daily conquers it anew.beats by dre outlet http://www.monsterbydreheadphones.us/


Top
 Profile  
 
 Post subject: Re: Error while using hibernate-4.0.1
PostPosted: Wed Mar 14, 2012 12:36 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
To the OP, for your case, and mine, you probably want to use the session.sessionWithOptions().transactionContext() if you're auditing changes. i.e. if your update fails you most likely want to roll back your audit changes as well.

Unfortunately, there's a bug with that functionality as well and is outlined at https://hibernate.onjira.com/browse/HHH-7090

_________________
Some people are like Slinkies - not really good for anything, but you still can't help but smile when you see one tumble down the stairs.


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