Ok. Thanks all. I understand the concept now. 

----- Original Message ----
From: Craig L Russell <[EMAIL PROTECTED]>
To: users@openjpa.apache.org
Sent: Monday, September 17, 2007 7:47:38 PM
Subject: Re: Flush Mode

Hi Gurkan,

JPA is designed to provide transaction isolation between  
EntityManagers. So, if two EntityManagers do not share the same  
transaction, changes made in one must not be visible in the other.

In your case, the query from the second EntityManager should not be  
able to see the changed made (but not committed) by the first  
EntityManager.

What the flush() method does is to write the changes to the database  
so they are visible to queries *made by the same EntityManager*.

Hope this clarifies what you're seeing.

Craig

On Sep 17, 2007, at 9:35 AM, Gurkan Erdogdu wrote:

> 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/

Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:[EMAIL PROTECTED]
P.S. A good JDO? O, Gasp!






       
____________________________________________________________________________________
Yahoo! oneSearch: Finally, mobile search 
that gives answers, not web links. 
http://mobile.yahoo.com/mobileweb/onesearch?refer=1ONXIC

Reply via email to