我相信你最終做要回調到當前事務的邊界內運行,你只是希望它運行後休眠已經做了的事情,就像休眠Envers工作。
要做到這一點,你基本上需要註冊一個事件動作隊列回調如下所示:
session.getActionQueue().registerProcess(
new BeforeTransactionCompletionProcess() {
@Override
public void doBeforeTransactionCompletion(SessionImplementor session) {
// do whatever you want with the session here.
}
}
);
如果你最終必須運行代碼外交易,你可以做同樣的事情:
session.getActionQueue().registerProcess(
new AfterTransactionCompletionProcess() {
@Override
public void doAfterTransactionCompletion(boolean success, SharedSessionContractImplementor session) {
// do whatever you want with the session here.
}
}
);
這應該讓你去任何一種方式。