program using hibernate does not terminate

I met this problem also today, and I found the solution is, in the end of your main method (or thread), you should close your Session Factory, like:

sessionFactory.close();

And then, your program will terminate normally.

If You use JavaFX 8 in main method add:

@Override
public void stop() throws Exception {
    sessionFactory.close();
}

This method will close session factory and destroy thread on program exit.


I had the same problem today, but I found another similar solution:

I inserted at the end of my code the following line:

StandardServiceRegistryBuilder.destroy(serviceRegistry);

And Ta-dah! the program ends.

Tags:

Java

Hibernate