thanks very much!
I have read the link article,but still confused because things in my test is unlike the ariticle mentions:
***********
Session session = getSessionFactory().openSession();
Long generatedId = session.save(item);
session.close();
This code results in an INSERT statement, executed inside a transaction that is never committed or rolled back. On Oracle, this piece of code inserts data permanently
************
but in my test , whether the autocommit is on or off, the record is never insert into the database when I'm not flush the session cache.
About
pb00067 wrote:
Which transaction demarcation approach do you use? Programmatic or declarative?
In first case the transaction should have been rollbacked, not commited.
I just open a session like the code I mention before, doesn't using beginTransation or Spring ,I know this is not a good way using hibernate ,I just want to understand autocommit;
Session session1 = sessionFactory.openSession();
Student st = new Student();
st.setName("mamyami");
session1.save(st);
session1.flush();
session1.close();
I used to think that when I flush the session in the code , the hibernate just take the sql to database,this behaviour likes you connect to your database with an SQL console and that you insert a row without typing begin a transaction and end a transaction with the sql.the record is actually inserted or not depends on autocommit; if you turn it on ,it inserted ;else it not. but if you not flush,hibernate will not take the sql to database,so the record will not inserted no matter autocommit is on or off;
but in my test is if you flush the cache ,no matter autocommit is on or off ,the record in inserted;
if you don't flush,no matter autocommit is on or off ,the record will not inserted;
is my test wrong?