transaction 与 session 区别

https://stackoverflow.com/questions/5409085/what-is-the-difference-between-a-session-and-a-transaction-in-jpa-2-0
and 谷歌翻译:


你去银行存了两张支票,然后取出一小笔钱。

所以你要排队,直到出纳员开门。

您进行了第一笔存款。
然后你的第二个。
然后你提款。

现在你完成了,你离开出纳线。

联系出纳员就像创建您的会话,现在您在银行,准备工作。

每次存款和取款都是他们自己包含的一组工作,这些是您的交易。

当您完成工作并离开时,您将关闭或放弃您的会话。


所以,本质上,一个会话包含你的交易,毕竟如果你不去银行,你就不能存入银行,对吗?


会话是用于与数据库交互的内容。

事务用于指定要在其中操作的会话的边界​​。

本质上,事务通过只允许一个会话一次与其交互来防止数据库被破坏。 (这有点复杂,因为您可以从数据库读取多个事务,但只有一个正在写入的事务。)


原文:

You go to the bank to deposit 2 checks, and withdraw a small sum.

So you stand in line until a teller opens.

You make your first deposit.
Then your second.
Then you make your withdrawal.

Now you’re done, you leave the teller line.

Getting to the teller is like creating your session, now you’re in the bank, ready to work.

Each deposit and withdrawal are their own contained set of work, these are your transactions.

When you’re done with your work and leave, you’re closing or abandoning your session.


So, in essence, a session contains your transactions, after all you can’t make a bank deposit if you never go to the bank right?


A session is what you use to interact with the database.

A transaction is used to specify boundaries for the session to operate within.

Essentially, transactions prevent the database from being corrupted by only allowing a session to interact with it at one time. (It’s a bit more complicated then that, as you can have many transactions reading from the database, but only one transaction that’s writing.)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值