2016-12-15 4 views
0

내 모든 데이터베이스 쿼리가 JPA로 수행되는 애플리케이션을 만들었습니다. 아래에 추가 된 코드 하나를 편집하는 방법이 있습니다.JPA 문제 동기화, 애플리케이션 재시작 필요

public static void setReservationAsUnactive(Reservation obj) { 
    em.getTransaction().begin(); 

    obj.setActive(0); 
    obj.setReturnedDate(new Date()); 
    em.merge(obj); 

    em.getTransaction().commit(); 
} 

나는 그러나, 변경하지가 조회 열이 내 MySQL 데이터베이스에 제대로 변경되는 것을 볼 수 있습니다,하지만 난 노력하겠습니다 때 JPA에서 그것을 꺼내 - 나는 응용 프로그램의를 다시 시작할 때 변경이 이루어집니다 ... 내가 꺼내는 데이터를 보장하려면 어떻게해야합니까? 신선한 데이터이고 캐시되지 않은 데이터는 무엇입니까?

답변

0

의견에 감사드립니다. 그러나 나는 그것을 원래부터 가져 와서 객체를 가져 와서 그것을 해결했습니다.

예 :

// this will work, and it will update the database, but the user need to restart his client to view the edited row 
public void btnSetReservationToUnactive() { 
    TableObject tableObject = getSelectedObject(); 
    ReservationBean.setReservationAsUnactive(ReservationBean.getReservationByID(tableObject.getID())); 

} 

// this method will update the current clients view also, because it get the object were it originally came from. 
// rather than getting a new object from the em. 
public void btnSetReservationToUnactive() { 
    TableObject tableObject = getSelectedObject(); 
    ReservationBean.setReservationAsUnactive(getReservationByIdFromTable(tableObject.getID())); 

} 

public Reservation getReservationByIdFromTable(int resID) { 
    for (Reservation res : customer.getReservationCollection()){ 
     if (res.getID() == resID) 
      return res; 
    } 

} 
1

당신은

em.getEntityManagerFactory().getCache().evict(theClass, thePrimaryKey); 

다른 솔루션은 캐시 저장 (나를 위해 나쁜 솔루션)을 삭제 한 캐시에서 개체를 퇴거해야합니다. Guide for disabling the cache storage

그리고 여기가 em.refresh(obj);

당신은 엔티티 관리자를 캐싱하는 경우 알려 주시기 바랍니다에 의한 기본 데이터베이스에서 개체를 얻을 수있는 documentation of the cache and how is stored in JPA

1

시도가 있습니까?

관련 문제