How to use SessionFactory in this case?

I have this JEE web application where if I check the tutor is not there then proceed to register the tutor follows by the subject.

So, in this case how do I use the SessionFactory and session such that I will not get the following error

INFO  [http-nio-8080-exec-1]: SessionFactory created.
INFO  [http-nio-8080-exec-1]: this is an error
java.lang.IllegalStateException: Transaction already active
	at org.hibernate.engine.transaction.internal.TransactionImpl.begin(
	at Business.RegisterService.isTutorExists(
	at Business.RegisterService.register(
	at controller.tutorController.doPost(

And I am getting the same error for the inserting subjects…

Because open the sessionFactory and close it on each of the methods does not work :frowning:

Does using Spring framework helps in my case?

I am a noob in Spring framework. And I am using Eclipse. Is there just a small library that is SessionFactory for hibernate that I can download and work from there ?

I’d appreciate it if you could point me to a easy to learn tutorial and it has to be maven JPA JEE.


First, you need to read the Hibernate User Guide.

Second, if you want to use Java EE, then you can should the Java EE docs and the application server docs as well.

You also mentioned Spring as well. So, if you want to use that, the Spring documentation will tell you everything you need to know. They also provide Getting Started guides which you can also find on the Spring framework website.