I am new in Hibernate, I still don't understand how does it work the Object import org.hibernate.Transaction;
.
Now I am writing CRUD operations for a Person
Entity, I wrote this implementation, basing on what I found on web:
public void save(Person p) {
Session session = this.sessionFactory.openSession();
Transaction tx = session.beginTransaction();
session.persist(p);
tx.commit();
session.close();
}
My question are, why I should use Transaction object? What happend if I don't use it? Finally, is required to use in every CRUD operations? I noticed that in read operations (so when we don't write in the DB and we got request only the list of Person object) developers don't put the code under transaction.