我不明白这些概念之间的区别。 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 的 TransactionSynchronization 接口(interface),该接口(interface)接收事务同步的回调。它具有各种方法,例如 afterCommit()
、afterCompletion()
、 beforeCommit()
根据事务状态调用。考虑一个实际示例,您希望在用户注册完成后向用户发送电子邮件,根据事务状态通知任何外部服务或记录任何特定的信息事件..
事务关联:我们基本上在 Activity 持久化上下文下提交事务..让它成为 JPA 的实体管理器或 Hibernate 的 session ..
我应该在不使用任何 JTA 事务的 Java SE 环境中关心它吗?是的..您将不得不退回到 JDBC 事务划分..
关于java - JPA 中的事务同步与事务关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45266595/