[Solved] Hibernate Program Not Terminating With Examples

Recently I was writing a small hibernate program and noticed that the program was not terminating even though main method is executed successfully. I was using Hibernate latest version 4.3.5.Final.

Hibernate Program Not Terminating Program

My sample class code is shown below.

The problem with above code is that Hibernate doesn’t release the resources and it’s our responsibility to release the resources once we are done with it.

As you can notice that in above program, ServiceManager instance is created but not closed.

So I changed the program to below code and the program started terminating fine after the main method is executed.

Notice that I am closing resources in finally block, so that even if application throws any exception all the resources are released.

By admin

Leave a Reply