public void method1 (){ EntityManager m = null; String result = null; EntityTransaction transaction = null; try{ m = SessionOperations.getEntityManager(); transaction = SessionOperations.getTransaction(m); transaction.begin(); m.setFlushMode(FlushModeType.AUTO); Query q = m.createQuery("select c from User c where c.oid=:oid"); q.setParameter("oid", getOid()); //Before set state = 'B' User s = (User)q.getResultList().get(0); s.setState('E');
m.flush(); //actually print update but not synch with DB method2(); }catch(Exception e){ transactionHandler(e, transaction); exceptionHandler(e); }finally{ if(transaction != null && transaction.isActive()) SessionOperations.commitTransaction(transaction); if(m != null) SessionOperations.closeEntityManager(m); } } public void method2(){ EntityManager m = null; try{ m = SessionOperations.getEntityManager(); Query q = m.createQuery("select c from User c where c.oid=:oid"); q.setParameter("oid", getOid()); User s = (User)q.getResultList().get(0); //In this user state still with 'B' }finally{ if(m != null) SessionOperations.closeEntityManager(m); } } persistence-xml just contains entity class definitions, and datasource specific properties. EJB 3.0 spec says that when entitymanager or query flush mode is AUTO then, all queries after that will contain new values. But I am not sure this is in the same entity manager, because in method1 and method2, I use two different entitymanager. ----- Original Message ---- From: Patrick Linskey <[EMAIL PROTECTED]> To: users@openjpa.apache.org Sent: Monday, September 17, 2007 6:37:48 PM Subject: Re: Flush Mode Can you post the actual code plus your persistence.xml file please? -Patrick On 9/17/07, Gurkan Erdogdu <[EMAIL PROTECTED]> wrote: > Hi; > > When I change User status in method1 using flush, it does not sync with the > database. It still looks the same status value in other method. > > public void method1(){ > EntityManager m; > EntityTransaction t; > > m.setFLushMode(AUTO); > t = m.gettransaction(); > t.begin; > Query q = some query to get User > > User user = q.getResultLsit(0); > user.setState('T'); > > m.flush(); //Actually write sql update to the console but not synch with > database > t.commit(); > > m.close; > > runNewQuery(); > } > > Then in runNewQueryMethod just select user with new status but seems status > not changed > > > EntityManager m; > Query q = some quety > > User user = get user > > but user status not changed. > > If I look console it prints, update sql to the database while flushing, but > not update to the database. > > What is the problem guys? > > > > ____________________________________________________________________________________ > Take the Internet to Go: Yahoo!Go puts the Internet in your pocket: mail, > news, photos & more. > http://mobile.yahoo.com/go?refer=1GNXIC > -- Patrick Linskey 202 669 5907 ____________________________________________________________________________________ Looking for a deal? Find great prices on flights and hotels with Yahoo! FareChase. http://farechase.yahoo.com/