Answer the question
In order to leave comments, you need to log in
How to solve Process finished with exit code 130 (interrupted by signal 2: SIGINT)?
Question, Why does the program have to be stopped manually?
I study Hibernate, wrote a couple of entities that work correctly and are created in the database, I wrote the correct closing of the session and SessionFactory, I did everything according to the tutorials, it is also clear in the Hibernate logs that everything works correctly, but the program has to be stopped manually, WHY? Explain, please.
After I stop manually in the console this
Process finished with exit code 130 (interrupted by signal 2: SIGINT)
Answer the question
In order to leave comments, you need to log in
session.beginTransaction() starts a new transaction, so in your code a new transaction is opened and immediately committed, while the old one will remain hanging.
Session session = sessionFactory.openSession();
Transaction tx;
try {
tx = session.beginTransaction();
Role hr = new Role();
hr.setRole("hr");
session.save(hr);
tx.commit();
}
catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
tx.rollback();
}
finally {
session.close();
HibernateUtil.shutdown();
System.out.println("after");
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question