2011-11-17 1 views
0

how to manually commit a Play! JPA transaction을 발견 한 후 ... 정말 필요가 있는지 확신 할 수 없습니다.이 재생을 수동으로 실행해야합니까? 트랜잭션?

저는 컨트롤러 액션이 두 개 있습니다. 하나는 웹 사이트를 추가하고 바로 다음 페이지로 리디렉션됩니다 ... 그 편집 폼을 보여줍니다.

public static void added(String title){ 
    Task task= new Task(); 
    website.title = title; 

    task.save(); 
    // Do I really need to commit this transaction here? 
    // Note that task.id is already filled here, somehow 
    // https://stackoverflow.com/questions/8169640/how-does-an-entity-get-an-id-before-a-transaction-is-committed-in-jpa-play 
    JPA.em().getTransaction().commit(); 

    edit(task.id); 
} 

public static void edit(long taskId) { 
    Task task = Task.find("byId", taskId).first(); 
    render(task); 
} 

edit()로 리디렉션하기 전에 트랜잭션을 커밋 할 필요가 있는가?

답변

2

아니요 :) (트랜잭션 처리를 제어해야 할 상황이있을 수 있지만이 중 하나가 아닌 것처럼 보일 수 있습니다. 또한 발견 한대로 Play!가 즉시 세션을 플러시합니다. 저장 후 자동으로 생성 된 PK ID에 액세스 할 수 있습니다.이 것이 유일한 시도 인 것처럼 보이므로 Play!가 할 일을하고 실제로 필요한 경우에만 제어권을 넘겨 줘야합니다.

+0

답장을 보내 주셔서 감사합니다. 질문. 공식 포럼 (Google 그룹스 외) – ripper234

관련 문제