Hibernate program does not end

I wrote a simple Hibernate program, and it seems to work fine, the data is loaded into the database, a table is created. However, the program does not exit after calling commit ().

Here is the code snippet I'm using:

    SessionFactory sessionFactory= new Configuration().configure().buildSessionFactory();
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    session.save(model);
    session.getTransaction().commit();

I use MySQL as a DB for this, running the program in eclipse.

Please imagine what might be wrong here.

Thanks vipin

+4
source share
2 answers
sessionFactory.close();

This is what you are looking for

+3
source

You are missing this (below):

session.close();

Final code:

SessionFactory sessionFactory= new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
session.save(model);
session.getTransaction().commit();
session.close(); //Here
0
source

Source: https://habr.com/ru/post/1539645/


All Articles