有用 BEAN Transaction ,請加上 begin(); commit();
Employee e = em.find(Employee.class, id);
try {
em.refresh(e);
} catch(EntityNotFoundException ex){
e = null;
}參考文件: http://weblogs.java.net/blog/guruwons/archive/2006/09/understanding_t.html
Employee e = em.find(Employee.class, id);
try {
em.refresh(e);
} catch(EntityNotFoundException ex){
e = null;
}Entity1 e = new Entity1();
// scenario 1
//交易開始
em.persist(e);
e.setField1(Value); // 交易結束後, Field1 會自動更新至資料庫
// scenario 2
// 交易開始
e = new MyEntity1();
em.merge(e);
e.setField1(anotherValue); // 交易結束後,Field1 不會更新至資料庫,除非你再作一次 merge
// scenario 3
// 交易開始
e = new Entity1();
Entity1 e2 = em.merge(e);
e2.setField1(anotherValue); // 交易結束後,Field1 會自動更新至資料庫,但是指 e2 不是 e