JPA 中的事务同步与事务关联

Transaction synchronization vs transaction association in JPA

我不明白这两个概念之间的区别。 Pro JPA 2 表示如下:

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 事务的 Java SE 环境中我应该关心它吗?感谢您的留言!

事务同步:你可以把它想象成Spring的事务同步接口,它接收事务同步的回调。它有各种方法,如afterCommit()afterCompletion()beforeCommit() 根据事务的状态调用。考虑一个实际示例,您希望在用户注册完成后向用户发送电子邮件,根据事务状态通知任何外部服务或记录任何特定事件..

Transaction association:we 基本上是在活跃的持久性上下文下提交事务..让它成为 JPA 的实体管理器或 Hibernate 的会话..

在不使用任何 JTA 事务的 Java SE 环境中我应该关心它吗?是的..你将不得不退回到 JDBC 事务划分..