我使用JPA和讓說我做這樣的事情JPA,範圍和自動保存?
public class MoRun extends Thread {...
public void run() {
final EntityManagerFactory emFactory = Persistence.createEntityManagerFactory("pu");
EntityManager manager = emFactory.createEntityManager();
manager.setFlushMode(FlushModeType.COMMIT);
someMethod(manager);
...
}
public void someMethod(EntityManager manager){
Query query = manager.createNamedQuery("byStates");
List<State> list = query.getResultList();
for (State state : list) {
if(someTest)
state.setValue(...)
}
...
}
因此,對於那些通過「someTest」對象和值被更新的那些變化自動保存到數據庫,即使沒有交易,我不要明確「manager.save(狀態)」的對象?我問,因爲它似乎是這樣,我想知道是否沖水是這樣做的?
你在哪裏運行這段代碼?你使用什麼'transaction-type'(RESOURCE_LOCAL或TRANSACTION)? – 2010-03-15 20:55:29