JPA 2.0中的会话和事务之间有什么区别? [英] What is the difference between a session and a transaction in JPA 2.0?

查看:107
本文介绍了JPA 2.0中的会话和事务之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


$ b

  em = SessionFactory.startSession()

我刚刚开始了我的JPA 2.0研究,并且有这段代码: ;
tx = em.getTransaction();

我的问题是:我不确定是否完全理解使用会话和交易的使用。在几行中,谁能告诉我他们之间最大的区别?谢谢!

解决方案

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

所以你排队等到出纳员打开。



你做了你的第一笔存款。
然后你的第二个。
然后你退出。



现在你完成了,你离开了取款线。



前往出纳员就像创建会话,现在你在银行,准备工作。



每次存款和提款都是他们自己的一套工作,这些都是您的交易。



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





因此,本质上讲,一个会话包含您的交易,毕竟如果您永远不会去银行,您无法存入银行存款吗?

I just begin my JPA 2.0 studies, and I have this piece of code:

em = SessionFactory.startSession();
tx = em.getTransaction();

My problem is: I'm not sure if I completly understand the difference between the use of a session and the use of a transaction. In a few lines, can anyone please tell me the biggest differences between them ? Thanks !

解决方案

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?

这篇关于JPA 2.0中的会话和事务之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆