Software/Atlassian
Transaction execute 코드 적용
LukeHan1128
2022. 10. 2. 20:00
반응형
기존 플러그인을 신규 구축한 Confluence 에 적용한 후 테스트를 진행하였으나 아래와 같은 에러가 발생 하였다.
org.springframework.orm.hibernate5.HibernateOptimisticLockingFailureException: Object of class [com.atlassian.confluence.pages.Page] with identifier [393407]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) : [com.atlassian.confluence.pages.Page#393407]
확인해 보니 Confluence 가 상위 버전으로 넘어가면서 Transaction 처리 방법이 변경되었다고 한다.
환경 구성
- Confluence 기존 버전 : 6.15.2
- Confluence 신규 버전 : 7.19.0
코드 적용 예시
package [...];
[...] // import api
import com.atlassian.sal.api.transaction.TransactionTemplate;
public class TestService{
// [...] // import bean
@ConfluenceImport
private final TransactionTemplate transactionTemplate;
@Autowired
public TestService(
// [...] ,
TransactionTemplate transactionTemplate){
// [...]
this.transactionTemplate = transactionTemplate;
}
public void transactionTest(){
transactionTemplate.execute(() -> {
// [...]
ttachmentManager.saveAttachment(...); // outter Transaction
// [...]
Page page = pageManager.getPage(pageId); // outter Transaction
Page originalPage = (Page) page.clone();
String content = page.getBodyAsString();
//modify content
page.setBodyAsString(content);
pageManager.saveContentEntity(page, originalPage, null); // outter Transaction
// [...]
return null;
});
}
}
반응형