Reputation: 5325
In Hibernate we close Session each time but is it necessary to close transaction each time in Hibernate or only transaction commit is sufficient?
Upvotes: 0
Views: 327
Reputation: 90527
We can only begin
, commit
or rollback
a transaction . So , closing
a transaction is ambiguous to me . Does it mean commit or rollback a transaction ?
If a transaction begins , a database connection will be established between the client and server . This connection will only be released if the transaction is committed , roll-backed or time-out (if database supports it) .
Calling session.close()
will call java.sql.Connection#close() . According to the JDBC specification , if java.sql.Connection#close() is called and there is an active transaction, the result of this active transaction depends on the JDBC vendor 's implementation. In case of Postgresql, it will automatically rollback . So it is strongly recommended that an application explicitly commits or rolls back an active transaction prior to session.close()
Upvotes: 1