Hibernate/c3p0: apparent deadlock

The apparent deadlock message issued by c3p0, a connection pool manager of Hibernate, can sometimes be misleading.

Most of the times, it is caused by connection errors.

So, check your firewall, and, for Postgresql  try the following command from the command line

If this works, you should have no problem connecting to Postgresql.

The apparent deadlock error

In my case I had the following error shown in the console under Windows, Java 8, when starting Tomcat under Eclipse Oxygen

and I was getting the following exception

In the postgres log I was seeing many authorized connections opened by c3p0.

I also used Wireshark and RawCap to capture the connections to the db and it seemed they were acquired, as the log said, but after seeing Postgres saying “ready for queries”, they were closed. I used this tutorial to understand how to use Wireshark with RawCap under Windows 10.

The solution

After some investigation I discovered I was using the wrong JDBC postgresql driver!

After changing to PostgreSQL JDBC 4.2 Driver, 42.1.4 which is listed as a driver for Java 8, all went fine.