为什么do we need Tran...
Notifications
Clear all

为什么do we need Transaction in Hibernate for read-only operations

RSS

(@sathish)
Member Moderator
Joined: 1 year ago
帖子:1391
12/05/2021 10:33 am

为什么do I need Transaction in Hibernate for read-only operations?

Does the following transaction put a lock in the DB?

Example code to fetch from DB:

Transaction tx = HibernateUtil.getCurrentSession().beginTransaction(); // why begin transaction? tx.commit() // why tx.commit? I don't want to write anything

Can I use session.close() instead of tx.commit()?


Quote
(@ganesh)
Noble Member
Joined: 1 year ago
Posts: 1362
12/05/2021 10:35 am

It doesn't matter whether you only read or not - the database must still keep track of your result set, because other database clients may want to write data that would change your result set.

I have seen faulty programs to kill huge database systems, because they just read data, but never commit, forcing the transaction log to grow, because the DB can't release the transaction data before a COMMIT or ROLLBACK, even if the client did nothing for hours.

Hope this is helpful!!


ReplyQuote
Share:
Baidu