Error accessing PooledConnection. Connection is invalid.

519 views
Skip to first unread message

jdevelop

unread,
Sep 6, 2016, 6:39:27 AM9/6/16
to mybatis-user
I have some problems with MyBatis 3.4.1, MyBatis Guice 3.6 and PostgreSQL 9.4. For some reason sometimes I have an exception:

org.apache.ibatis.exceptions.PersistenceException Error during getting and compressing a project: {} 
### Error committing transaction.  Cause: java.sql.SQLException: Error accessing PooledConnection. Connection is invalid.
### Cause: java.sql.SQLException: Error accessing PooledConnection. Connection is invalid.
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSession.commit(DefaultSqlSession.java:227)
at org.apache.ibatis.session.SqlSessionManager.commit(SqlSessionManager.java:297)
at org.mybatis.guice.transactional.TransactionalMethodInterceptor.invoke(TransactionalMethodInterceptor.java:125)

My current configuration for the connection manager looks like:

           <dataSource type="POOLED">
               
<property name="driver" value="org.postgresql.Driver"/>
               
<property name="url" value="jdbc:postgresql://${JDBC.host}:${JDBC.port}/${JDBC.schema}"/>
               
<property name="username" value="${JDBC.username}"/>
               
<property name="password" value="${JDBC.password}"/>
               
<property name="poolMaximumActiveConnections" value="30"/>
               
<property name="poolMaximumIdleConnections" value="10"/>
               
<property name="poolPingEnabled" value="true"/>
               
<property name="poolPingQuery" value="select 1"/>
           
</dataSource>

What could cause this error and how do I fix it?

Thanks!

Jose María Zaragoza

unread,
Sep 6, 2016, 1:05:07 PM9/6/16
to mybati...@googlegroups.com
Hi:

Well, I'm not sure, but there is a parameter called
poolMaximumCheckoutTime, that according to MyBatis documentation

poolMaximumCheckoutTime – This is the amount of time that a Connection
can be "checked out" of the pool before it will be forcefully
returned. Default: 20000ms (i.e. 20 seconds)

I don't know if this parameter is equal to validationInterval of JDBC
Connection Pool .
I'd got an error like yours if validationInterval is set to default
time ( 20 seconds ) and the database server is down randomly.
I tested to set a lower value ( 5 seconds ) and "Connection is
invalid" error was gone.
But the root of the problem was the database link connection, so I set
validationInterval to 20 seconds again ( by performance reasons )



> Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups
> "mybatis-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mybatis-user...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages