JPA中的java事务同步与事务关联
我不明白这两个概念之间的区别。支持JPA2的人士说:
Transaction synchronization is the process by which a persistence context is registered with a transaction so that the persistence context can be notified when a transaction commits. The provider uses this notification to ensure that a given persistence context is correctly flushed to the database.
Transaction association is the act of binding a persistence context to a transaction. You can also think of this as the active persistence context within the scope of that transaction.
请你再解释一下,也许是一些实际的例子好吗?在不使用任何JTA事务的JavaSE环境中,我应该关心它吗?谢谢你的留言
# 1 楼答案
事务同步:您可以将其视为Spring的TransactionSynchronization接口,它接收事务同步的回调。。它有各种各样的方法,如
afterCommit()
、afterCompletion()
、beforeCommit()
,它们根据事务的状态被调用。。考虑一个实际的例子,您希望在用户注册完成后发送电子邮件给用户,根据事务状态通知任何外部服务或记录任何特定事件。p>事务关联:我们基本上在活动持久性上下文下提交事务。。让它成为JPA的实体管理器或Hibernate的会话
在不使用任何JTA事务的JavaSE环境中,我应该关心它吗?对您将不得不退回到JDBC事务划分