本文介绍了什么是数据库会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我理解数据库事务概念的一般理解。我们访问事务内的数据库以确保ACID属性。

在Hibernate中有一个叫做session的概念。会议有什么用途?什么时候应该在两个会话中进行数据库访问而不是在同一个会话中?



为了解释更多,我已经看到了hibernate代码




  • 从会话工厂获取会话
  • 打开会话

  • 开始交易
  • >
  • 提交交易

  • 关闭会话



需要知道这里的会话的重要性是什么?为什么没有像事务工厂那样的东西,开始事务和提交事务? 解决方案

实施模式。换句话说,它可以保持已加载的对象,知道哪些对象必须被持久保存等。

到更好地理解Session和Transaction之间的关系,你可以看看。


I understand a general understanding of the concept of a database transaction. We access a database within transaction to ensure ACID properties.

In Hibernate there is a concept called a session. What is the use of a session? When should database access happen in two sessions rather than in the same session?

To explain more, I have seen hibernate code that

  • gets a session from a session factory
  • opens a session
  • begins a transaction
  • commits the transaction
  • closes the session

What I need to know is what is the importance of a session here? Why not have something like a transaction factory, begin transaction and commit transaction?

解决方案

Session is more than just a transaction, it is an implementation of UnitOfWork pattern. In other words it holds on to the loaded objects, knows which objects has to be persisted etc:

To better understand relation between Session and Transaction you can take a look at this article.

这篇关于什么是数据库会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 02:37