-->
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: Hibernate sporadically looses connection
PostPosted: Wed Oct 29, 2008 1:33 pm 
Beginner
Beginner

Joined: Tue Aug 17, 2004 5:06 am
Posts: 46
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.2.3ga

Full stack trace of any exception that occurs:
java.lang.NullPointerException
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:505)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:423)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1547)
at org.hibernate.loader.Loader.doQuery(Loader.java:673)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2136)
at org.hibernate.loader.Loader.list(Loader.java:2096)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at org.hibernate.impl.CriteriaImpl.uniqueResult(CriteriaImpl.java:305)
at de.vdb.testapp.dao.ApplicationPropertyDaoBase$2.doInHibernate(ApplicationPropertyDaoBase.java:418)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:339)
at de.vdb.testapp.dao.ApplicationPropertyDaoBase.findByUkProp(ApplicationPropertyDaoBase.java:408)
at de.vdb.testapp.dao.ApplicationPropertyDaoBase.findByUkProp(ApplicationPropertyDaoBase.java:380)
at de.vdb.testapp.dao.ApplicationPropertyDao.findByName(ApplicationPropertyDao.java:51)
at de.vdb.testapp.dao.ApplicationPropertyDao.findBooleanValue(ApplicationPropertyDao.java:170)

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

We have some strange problem with Hibernate and Oracle 10g. Under heavy load Hibernate tends to loose the database connection from time to time (see the stacktrace).

From the Hibernate sources:
Code:
private PreparedStatement getPreparedStatement(...)
...
line 505: result = conn.prepareStatement( sql );
}


The connection pool configuration in Tomcat:
Code:
<Resource name="jdbc/db_test2" auth="Container" type="oracle.jdbc.pool.OracleDataSource"
              debug="0"
              factory="oracle.jdbc.pool.OracleDataSourceFactory"
              url="jdbc:oracle:thin:@db_test2:1521:dbtest"
              connectionCachingEnabled="true"
              connectionCacheName="dbtest2"
              connectionCacheProperties="{MinLimit=0, MaxLimit=20, InitialLimit=0}"
              user="xxx"
              password="xxx"
              />


Obviously the connection is null.

This might be a problem with Hibernate, with the connection pool (we use Tomcat's internal connection pooling) or the database driver.
After short time the connection is available again.

Any hints ?


Top
 Profile  
 
 Post subject: Re: Hibernate sporadically looses connection
PostPosted: Tue Jun 01, 2010 6:27 am 
Newbie

Joined: Tue Jun 01, 2010 6:20 am
Posts: 5
I am also getting the similar type of exception? Could you please let me know, what needs to be done for this? i am using hibernate 3.2.3ga version.


Top
 Profile  
 
 Post subject: Re: Hibernate sporadically looses connection
PostPosted: Tue Jun 01, 2010 8:13 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
jdbc connections are not reliable, that's why you shouldn't rely on Tomcat alone.
If you need to use Tomcat you'll have to use a connection pool like c3p0 (there are lots of guides online to use hibernate with c3p0).
Otherwise, use an application server, there you can configure nice settings to use reliable and monitored connections.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Hibernate sporadically looses connection
PostPosted: Wed Jun 02, 2010 1:03 am 
Newbie

Joined: Tue Jun 01, 2010 6:20 am
Posts: 5
Sorry I am using resin server (application server), not tomcat.
The following db configuration, we are using in resin.
<resource jndi-name="financedb" type="oracle.jdbc.pool.OracleDataSource">
<init><url>DB URL</url>
<user>user name</user>
<password>pass word</password>
<fast-connection-failover-enabled>true</fast-connection-failover-enabled>
<connection-caching-enabled>true</connection-caching-enabled>
<connection-cache-properties>
MinLimit=0
MaxLimit=10
InitialLimit=1
InactivityTimeout=1800
AbandonedConnectionTimeout=900
ConnectionWaitTimeout=60
ValidateConnection=true
Validate-connection-statement="select 1 from dual;"
</connection-cache-properties>
</init>
</resource>


Top
 Profile  
 
 Post subject: Re: Hibernate sporadically looses connection
PostPosted: Wed Jun 02, 2010 4:54 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
while I don't know Resin, this seems to make sense:
Quote:
ValidateConnection=true
Validate-connection-statement="select 1 from dual;"

Which hibernate version? it shouldn't really throw a nullpointer there.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Hibernate sporadically looses connection
PostPosted: Wed Jun 02, 2010 4:59 am 
Newbie

Joined: Tue Jun 01, 2010 6:20 am
Posts: 5
Which hibernate version? it shouldn't really throw a nullpointer there. --
I am using 3.2.3ga -- Hibernate Version -- I am getting the nullpointer exception spordically.

By using these two tags we are validating, whether the connection is valid or not...
ValidateConnection=true
Validate-connection-statement="select 1 from dual;"


Top
 Profile  
 
 Post subject: Re: Hibernate sporadically looses connection
PostPosted: Wed Jun 02, 2010 5:12 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
I am using 3.2.3ga -- Hibernate Version -- I am getting the nullpointer exception spordically.

ok sorry for asking I was assuming you where using something newer than the original thread poster.
That's very old! you should try upgrading, there have been thousands of improvements and bugfixes after that.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Hibernate sporadically looses connection
PostPosted: Wed Jun 02, 2010 5:27 am 
Newbie

Joined: Tue Jun 01, 2010 6:20 am
Posts: 5
Without upgrading the hibernate version..can't we able to fix this issue? Because if i upgrade the version, we have to test the all the scenerios...This is very huge.

And one morething, I am getting the exception in 505 line.

Code:
private PreparedStatement getPreparedStatement(...)
...
line 505: result = conn.prepareStatement( sql );
}


Could you please let me know, why i am getting the Null Pointer Exception in this line?

Any hints?


Top
 Profile  
 
 Post subject: Re: Hibernate sporadically looses connection
PostPosted: Wed Jun 02, 2010 5:50 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
of course it means the connection was null; it's hard to track why; you might want to debug it.
Anyway even if we could fix that, you would have to change version.

Quote:
Because if i upgrade the version, we have to test the all the scenerios...This is very huge.

that's why you should have automated tests, or you will be locked forever in the fear of changing any library.

Anyway you might want to at least upgrade to the latest supported hibernate 3.2.X instead of switching to 3.5.2 (which is the latests), so you should minimize risk and still get a load of issues fixed. There's a 3.2.7 and there are also extra-stable supported packages provided by Red Hat support which contain only backported fixes and attempt to avoid all breaking changes (I don't work for RH, but this might be a solution for you).

Try a drop-in of 3.2.7; remember to upgrade also depending libraries from the 3.2.7 download package.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Hibernate sporadically looses connection
PostPosted: Thu Jun 03, 2010 5:01 am 
Newbie

Joined: Tue Jun 01, 2010 6:20 am
Posts: 5
Can we know, what are the changes have done in 3.2.7 vesrion?

Do we have any fix for this Null Pointer exception or memory leak in 3.2.7 version?

Code:
private PreparedStatement getPreparedStatement(...)
...
line 505: result = conn.prepareStatement( sql );
}


Top
 Profile  
 
 Post subject: Re: Hibernate sporadically looses connection
PostPosted: Thu Jun 03, 2010 8:27 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
All changes, bugfixes and new features are tracked on JIRA.

_________________
Sanne
http://in.relation.to/


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.