我想清除基本的3点,
Does beginning a new database transaction on an old session obtains a new connection and resumes the session?
Does committing a database transaction disconnects a session from the JDBC connection and returns the connection to the pool?
From Hibernate Documentation, earlier versions of Hibernate required explicit disconnection and reconnection of a Session. These methods are deprecated, asbeginning and ending a transaction has the same effect. How do they have the same effect?
最佳答案
Hibernate Session 只是一个事务性的后写缓存,它将实体状态转换转换为 DML 语句。 Hibernate Session 可以与数据库连接或断开连接。当它断开连接时,它无法将当前挂起的实体状态更改刷新到底层数据库。
associate a Hibernate Session to a database transaction有多种方式:
对于数据库事务,有两种不同的方法:
现在回到你的问题:
- Does beginning a new database transaction on an old session obtains a new connection and resumes the session?
是的。 Hibernate session 重新连接并且可以继续刷新/提交。
- Does committing a database transaction disconnects a session from the JDBC connection and returns the connection to the pool?
默认情况下,当您提交事务时, session 关闭,底层连接关闭。如果使用连接池,数据库连接确实会返回池中。
- From Hibernate Documentation, earlier versions of Hibernate required explicit disconnection and reconnection of a Session. These methods are deprecated, as the beginning and ending of a transaction have the same effect. How do they have the same effect?
这些方法已被弃用,因为 connection management现在由 connection release modes 控制.
关于hibernate - Hibernate 中的 session 和连接有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28486850/