Was ist die Transaktion.commit() in den Ruhezustand?

Was bedeutet Transaktion.commit() tun?

Account account = new Account();
account.setId(100);
account = (Account) session.get(Account.class, account.getId());
System.out.println("Before Transaction: Balance = " + account.getBalance());
double preBal = account.getBalance();
account.setBalance(50000000);
Transaction transaction = session.beginTransaction();
session.update(account);
account = (Account) session.get(Account.class, account.getId());
System.out.println("After Transaction: Balance = " + account.getBalance());
//transaction.commit();    
account = (Account) session.get(Account.class, account.getId());
System.out.println("Pev-Bal=" + preBal + " Curr-Bal=" + account.getBalance());

Gibt mir das Ergebnis:

Hibernate: select account0_.id as id0_1_, account0_.balance as ..........
Before Transaction: Balance = 300.0
After Transaction: Balance = 5.0E7
Pev-Bal=300.0 Curr-Bal=5.0E7

Da ich aber nicht nennen Transaktion.commit() es gab keine änderung in der Datenbank.

Dies bedeutet alles, was getan wurde, nur auf manche Instanzen/Objekte, ohne Sie wirklich ändern die Datenbank?

Ich bin neu in den Ruhezustand, so bitte helfen Sie mir zu verstehen.
Ich bin mit hibernate 4.

UPDATE:

WENN ich rufe, Transaktion.commit() dann ist das Ergebnis dieser Zeile

Hibernate: update account set balance=? where id=?

Und die Datenbank ebenfalls aktualisiert.

Bedeutet dies, dass ohne Aufruf Transaktion.commit() alles getan wurde, nur auf Instanz-Ebene, ohne Sie wirklich ändern die Datenbank?

InformationsquelleAutor Mawia | 2013-01-31
Schreibe einen Kommentar