c3p0 with squeryl, im calling .close() too many times

293 views
Skip to first unread message

Jason MacLulich

unread,
Jul 23, 2013, 11:02:00 PM7/23/13
to squ...@googlegroups.com
Hi Guys,

I'm integrating c3p0 into my session management as I'm currently spamming mySQL with too many new connections per second.

I'm following this sample:


and it appears to be working...however I see these in my logs now:

com.mchange.v2.c3p0.impl.NewProxyPreparedStatement@6dcad662: close() called more than once.

I think this is being called whenever I have a transaction statement.

transaction {


}

then the close() more than once is in my logs.

Does this mean the connection pool is calling close() and the transaction statement is calling close() after the statement has finished executing?

Thanks, Jason.

Jason MacLulich

unread,
Jul 23, 2013, 11:07:17 PM7/23/13
to squ...@googlegroups.com

I've been looking at the source for c3p0 a bit more and it looks like in the close() call it does this:

catch (NullPointerException exc)
			if ( this.isDetached() )
					logger.logMLevel.FINEthis + ": close() called more than once." );
			else throw exc;


This is what's logging the close() called more than once.

I'm getting a NullPointerException thrown somewhere..during the close() method.

Jason MacLulich

unread,
Jul 23, 2013, 11:20:11 PM7/23/13
to squ...@googlegroups.com

Actually, I think it's because of this check:

	boolean isDetached()
return (this.parentPooledConnection == null); }

the parentPooledConnection is already NULL, but I don't know why.

Vasya Novikov

unread,
Jul 24, 2013, 4:17:59 AM7/24/13
to squ...@googlegroups.com
I'm using c3p0 with squeryl and I have no such problem.

There must be something special about how you use it. Maybe you just call "close()" in your custom code?

Jason MacLulich

unread,
Jul 24, 2013, 9:32:02 PM7/24/13
to squ...@googlegroups.com

Thanks Vasya.

One of my problems is that I can't really find a tutorial that steps through integrating it properly, lots of fragments of code with "and now your done." at the end :)

Couple of questions, are you using 

transaction {

}

and then modifying the squeryl factory class to something like this?

SessionFactory.concreteFactory = Some(() => getConnection)

where getConnection is making a call to the connection pool, something like:

def getConnection = {
  Session.create(cpds.getConnection, new MySQLAdapter)
}

I think I've narrowed it down to the following 2 scenarios:
 o if I use the connection pool from a singleton I don't get the double close
 o if I use it in a case class I get the double close.

Would appreciate any pointers.

Thanks, Jason.

Vasya Novikov

unread,
Aug 18, 2013, 4:35:25 AM8/18/13
to squ...@googlegroups.com
I'm sorry, I must be already late with the answer. I'll answer anyway, "for history"...


> Couple of questions, are you using 
> transaction {
> }
> and then modifying the squeryl factory class to something like this?
> SessionFactory.concreteFactory = Some(() => getConnection)

Well, first I use the "concreteFactory = Some()" thing. This is when the application loads, so only once.
And after that, as a normal regular operation I use a transaction{} block.

The exact code looks like this:
        SessionFactory.concreteFactory = {
            Some(() => Session.create(pool.getConnection, squerylAdapter))
        }

(I didn't use a def, just inlined the thing.)
Reply all
Reply to author
Forward
0 new messages