Got some bunch of code:
Session session = sessionFactory.openSession();
Transaction tx = session.getTransaction();
try
{
tx.begin();
Person person = Person.builder().name("JAN").surname("NOWAK").age(30).build();
session.save(person);
tx.commit();
}
While debugging i see that person is reflected in data base before transaction commit. I set explicitly
<property name="hibernate.connection.autocommit">false</property>
and tried with various hibernate versions but still get the issue.
Even if i throw Exception before commit
try
{
tx.begin();
Person person = Person.builder().name("JAN").surname("NOWAK").age(30).build();
session.save(person);
String s = null;
if (s == null) {
throw new Exception();
}
tx.commit();
}
Result is the same, Person is added to DB whether I use tx.commit() or NOT.
EDIT:
After changing entity generating strategy from IDENTITY to AUTO it works as I anticipated before, changes in DB are made after commit. Result:
Hibernate: select next_val as id_val from hibernate_sequence for update
Hibernate: update hibernate_sequence set next_val= ? where next_val=?
sout: tx.commit()
Hibernate: insert into Person (age, name, surname, id) values (?, ?, ?, ?)
But could anyone explain why so?