I am running an application on the command line with the gradle application plugin and the ‘run’ task. It connects to a database and does transactions using a JPA EntityManagerFactory and EntityManagers. One issue I am seeing is that quite often when I ctrl+c the application and it is mid-transaction, it leaves behind the connection in postgres. I tried adding a shutdown hook to the application to close the entityManagerFactory, but that does not seem to help, it seems as if the shutdown hook is not running.
Any advice?