2012-06-14 37 views
2

我正在使用EJB3,並且遇到與刷新我的EntityManager有關的問題。使用JPA連接刷新

問題是,我的apllication必須準備好供很多人使用,但是如果一個人更新同一日期,那麼EntityManager不會佔用那一行,並且它看不到其他人在x分鐘後做的更改。

有沒有人知道如何刷新EntityManager當我做'選擇','插入','更新'或'刪除'?

+0

爲防止上次寫入勝?或在此之前? – ssedano

回答

0

這是一個併發問題,您應該閱讀JPA Specification關於鎖定和併發的第3.4節。這包括樂觀和寬容的鎖定以及使用版本化屬性。

附加3.2.5節介紹瞭如何刷新實體實例。

0

嘗試刷新一個實體。例如:

public void create(MyEntity entity) { 
    getEntityManager().persist(entity); 
    getEntityManager().flush(); 
    getEntityManager().refresh(entity); 
} 

public void edit(MyEntity entity) { 
    getEntityManager().merge(entity); 
    getEntityManager().flush(); 
    getEntityManager().refresh(entity); 
} 

希望這會有所幫助。

+0

如果你想在選擇???? – Xavier