동일한 거래 엔티티로 2 개의 다른 DB 호출을하려고합니다. begin()
과 commit()
사이에서 두 가지 질문을 할 수 있다는 것을 알고 있지만 교육적인 목적으로 만 시도하고 있습니다.JPA : multiple transactions
EntityTransaction transaction = em.getTransaction();
EventService eventService = new EventService();
transaction.begin();
Event currentEvent = eventService.read(eventId);
transaction.commit();
if (currentEvent != null){
CommentService commentService = new CommentService();
transaction.begin();
commentList = commentService.getList(1, id, 50);
transaction.commit();
}
이 코드 조각을 던졌습니다 :
예외 설명 : 트랜잭션은 현재 활성화되어 내가 이미 열려 거래에
begin()
을 시도하고있어 것을 알고 정상
.
두 번째 transaction.begin()
을 제외하고 DB로 작업해야 할 때마다 commit()
을 사용하는 것이 맞습니까?
LE : 내가는 EclipseLink 및 RESOURCE_LOCAL
입니다()? – MaDa
같은 일이 발생합니다. 첫 번째 .begin() 이후 .isActive()는 EntityManager를 닫을 때까지 항상 true를 반환합니다. – Ionut
em.getClass() 및 transaction.getClass()를 인쇄하여 어떤 구현이 사용되고 있는지 확인할 수 있습니까? EclipseLink의 트랜잭션 구현은 트랜잭션을 commit()의 finally 블록에서 비활성으로 표시하므로 래퍼가 직접 호출을 전달하지 않을 수 있습니다. 사용중인 EclipseLink 버전은 무엇입니까? – Chris