You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Johnson <jo...@soho.club.tw> on 2005/06/14 02:39:02 UTC

org.odmg.LockNotGrantedException

Hi!

I try to upgrade my ojb in cocoon from 1.0.1 to 1.0.3.
when I save a record and then read the record(or others) the system got an error
org.odmg.LockNotGrantedException
If I use another session to read it ok,But the record I wrote never change.
the objectcache I use in 1.0.1 is org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl
and 1.0.3 I use the same or ObjectCacheTwoLevelImpl it read ok then write no error(but database no record) and then read again and got the error.
is there something I'm wrong?

Best Regards

Johnson

Re: org.odmg.LockNotGrantedException

Posted by 許議中 <jo...@soho.club.tw>.
will test later then reply tthe result in a few days,tks.

Best Regards

johnson
----- Original Message ----- 
From: "Armin Waibel" <ar...@apache.org>
To: "OJB Users List" <oj...@db.apache.org>
Sent: Tuesday, June 14, 2005 9:47 PM
Subject: Re: org.odmg.LockNotGrantedException


> Hi again,
> 
> Johnson wrote:
>> Hi!
>> 
>> tks your help I use OJB in cocoon tmocat here's the code.
>> this code is work on 1.0.1 but not work in 1.0.3.
>> 
> 
> I can't reproduce the problem with latest from CVS (OJB_1_0_RELEASE
> branch). I wrote two tests simulating the problem, first test doesn't
> find a query object and lock the bean object, second test return a dummy
> object in query. Both tests pass.
> 
> I attached the tests below (the test can be found in CVS OJB_1_0_RELEASE
> branch, LockingTest#testWrite_X). Are these tests different from your
> problem? Could you locally setup a test case to reproduce the problem?
> Are you able to test upcoming OJB 1.0.4 from CVS?
> 
> regards,
> Armin
> 
> 
> 
> 
> public void testWrite_1() throws Exception
> {
>    String name = "testWrite_1_" + System.currentTimeMillis();
>    LockObject bean = new LockObject(name + "_bean_dummy");
> 
>    performCocoonSaveMethod(bean.getId(), bean);
> 
>    Transaction tx = odmg1.newTransaction();
>    tx.begin();
>    OQLQuery query = odmg1.newOQLQuery();
>    query.create("select objs from " + LockObject.class.getName() + "
> where value = $1");
>    query.bind(name + "_bean_dummy");
>    List result = (List) query.execute();
>    tx.commit();
>    assertEquals(1, result.size());
>    LockObject tmp = (LockObject) result.get(0);
>    assertEquals(bean, tmp);
> }
> 
> public void testWrite_2() throws Exception
> {
>    String name = "testWrite_2_" + System.currentTimeMillis();
> 
>    Transaction tx = odmg1.newTransaction();
>    tx.begin();
>    LockObject tmp = new LockObject(name + "_temp");
>    db1.makePersistent(tmp);
>    tx.commit();
> 
>    LockObject bean = new LockObject(name + "_bean_dummy");
>    bean.setId(tmp.getId());
> 
>    performCocoonSaveMethod(tmp.getId(), bean);
> 
>    tx = odmg1.newTransaction();
>    tx.begin();
>    OQLQuery query = odmg1.newOQLQuery();
>    query.create("select objs from " + LockObject.class.getName() + "
> where value = $1");
>    query.bind(name + "_bean_dummy");
>    List result = (List) query.execute();
>    tx.commit();
>    assertEquals(1, result.size());
>    tmp = (LockObject) result.get(0);
>    assertEquals(bean, tmp);
> }
> 
> private LockObject performCocoonSaveMethod(Integer testId, LockObject
> bean) throws Exception
> {
>    LockObject toBeEdited = null;
>    Transaction tx = odmg1.newTransaction();
>    tx.begin();
>    OQLQuery query = odmg1.newOQLQuery();
>    query.create("select objs from " + LockObject.class.getName() + "
> where id = $1");
>    query.bind(testId);
>    List result = (List) query.execute();
>    if(result.size() != 0)
>    {
>        toBeEdited = (LockObject) result.get(0);
>        if(toBeEdited != null)
>        {
>            try
>            {
>                PropertyUtils.copyProperties(toBeEdited, bean);
>                tx.commit();
>            }
>            catch(Exception e)
>            {
>                e.printStackTrace();
>                fail("Unexpected exception: " + e.getMessage());
>            }
>            tx.begin();
>            tx.lock(toBeEdited, Transaction.UPGRADE);
>            tx.commit();
>        }
>        else
>        {
>            tx.abort();
>        }
>    }
>    else
>    {
>        try
>        {
>            tx.lock(bean, Transaction.WRITE);
>            tx.commit();
>        }
>        catch(Exception e)
>        {
>            e.printStackTrace();
>            fail("Unexpected exception: " + e.getMessage());
>        }
>    }
>    return toBeEdited;
> }
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: org.odmg.LockNotGrantedException

Posted by Armin Waibel <ar...@apache.org>.
Hi again,

Johnson wrote:
> Hi!
> 
> tks your help I use OJB in cocoon tmocat here's the code.
> this code is work on 1.0.1 but not work in 1.0.3.
> 

I can't reproduce the problem with latest from CVS (OJB_1_0_RELEASE
branch). I wrote two tests simulating the problem, first test doesn't
find a query object and lock the bean object, second test return a dummy
object in query. Both tests pass.

I attached the tests below (the test can be found in CVS OJB_1_0_RELEASE
branch, LockingTest#testWrite_X). Are these tests different from your
problem? Could you locally setup a test case to reproduce the problem?
Are you able to test upcoming OJB 1.0.4 from CVS?

regards,
Armin




public void testWrite_1() throws Exception
{
    String name = "testWrite_1_" + System.currentTimeMillis();
    LockObject bean = new LockObject(name + "_bean_dummy");

    performCocoonSaveMethod(bean.getId(), bean);

    Transaction tx = odmg1.newTransaction();
    tx.begin();
    OQLQuery query = odmg1.newOQLQuery();
    query.create("select objs from " + LockObject.class.getName() + "
where value = $1");
    query.bind(name + "_bean_dummy");
    List result = (List) query.execute();
    tx.commit();
    assertEquals(1, result.size());
    LockObject tmp = (LockObject) result.get(0);
    assertEquals(bean, tmp);
}

public void testWrite_2() throws Exception
{
    String name = "testWrite_2_" + System.currentTimeMillis();

    Transaction tx = odmg1.newTransaction();
    tx.begin();
    LockObject tmp = new LockObject(name + "_temp");
    db1.makePersistent(tmp);
    tx.commit();

    LockObject bean = new LockObject(name + "_bean_dummy");
    bean.setId(tmp.getId());

    performCocoonSaveMethod(tmp.getId(), bean);

    tx = odmg1.newTransaction();
    tx.begin();
    OQLQuery query = odmg1.newOQLQuery();
    query.create("select objs from " + LockObject.class.getName() + "
where value = $1");
    query.bind(name + "_bean_dummy");
    List result = (List) query.execute();
    tx.commit();
    assertEquals(1, result.size());
    tmp = (LockObject) result.get(0);
    assertEquals(bean, tmp);
}

private LockObject performCocoonSaveMethod(Integer testId, LockObject
bean) throws Exception
{
    LockObject toBeEdited = null;
    Transaction tx = odmg1.newTransaction();
    tx.begin();
    OQLQuery query = odmg1.newOQLQuery();
    query.create("select objs from " + LockObject.class.getName() + "
where id = $1");
    query.bind(testId);
    List result = (List) query.execute();
    if(result.size() != 0)
    {
        toBeEdited = (LockObject) result.get(0);
        if(toBeEdited != null)
        {
            try
            {
                PropertyUtils.copyProperties(toBeEdited, bean);
                tx.commit();
            }
            catch(Exception e)
            {
                e.printStackTrace();
                fail("Unexpected exception: " + e.getMessage());
            }
            tx.begin();
            tx.lock(toBeEdited, Transaction.UPGRADE);
            tx.commit();
        }
        else
        {
            tx.abort();
        }
    }
    else
    {
        try
        {
            tx.lock(bean, Transaction.WRITE);
            tx.commit();
        }
        catch(Exception e)
        {
            e.printStackTrace();
            fail("Unexpected exception: " + e.getMessage());
        }
    }
    return toBeEdited;
}

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: org.odmg.LockNotGrantedException

Posted by Johnson <jo...@soho.club.tw>.
Hi!

tks your help I use OJB in cocoon tmocat here's the code.
this code is work on 1.0.1 but not work in 1.0.3.

    public int save(Sa1 bean, Implementation impl)
    {
       int cnt = 0;
        Database db = impl.newDatabase();
        try {
          db.open("sy", Database.OPEN_READ_WRITE);
          Transaction tx = impl.newTransaction();
          tx.begin();
          OQLQuery query = impl.newOQLQuery();
          query.create("select sa1s from " + Sa1.class.getName() + " where 
sa1_ord = $1");
          query.bind(bean.getSa1_ord());
          DList result = (DList) query.execute();
          cnt = result.size();
          if (cnt != 0) {
              Sa1 toBeEdited = (Sa1) result.get(0);
              if (toBeEdited != null) {
               try {
                  PropertyUtils.copyProperties(toBeEdited,bean);
  tx.commit();
               } catch (Throwable t) {}
 tx.begin();
               tx.lock(toBeEdited, Transaction.UPGRADE);
              tx.commit();
 }
              else {tx.abort();}
           }
         else {
 try {
            tx.lock(bean, Transaction.WRITE);
            tx.commit();
         }catch (Throwable t) {}
            }
             db.close();
        }
        catch (ODMGException ex) {}
        return cnt;
    }

Best Regards

----- Original Message ----- 
From: "Armin Waibel" <ar...@apache.org>
To: "OJB Users List" <oj...@db.apache.org>
Sent: Tuesday, June 14, 2005 3:31 PM
Subject: Re: org.odmg.LockNotGrantedException


> Hi Johnson,
>
> could you please post some (pseudo) code so that I can write a test to
> reproduce your locking problem. Is OJB running in a managed (e.g. using
> an appServer with JTA) or non-managed environment.
>
>> If I use another session to read it ok,But the record I wrote never
>> change.
>
> sounds as the record was not committed.
>
> regards,
> Armin
>
>
> Johnson wrote:
>> Hi!
>>
>> I try to upgrade my ojb in cocoon from 1.0.1 to 1.0.3.
>> when I save a record and then read the record(or others) the system got 
>> an error
>> org.odmg.LockNotGrantedException
>> If I use another session to read it ok,But the record I wrote never 
>> change.
>> the objectcache I use in 1.0.1 is 
>> org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl
>> and 1.0.3 I use the same or ObjectCacheTwoLevelImpl it read ok then write 
>> no error(but database no record) and then read again and got the error.
>> is there something I'm wrong?
>>
>> Best Regards
>>
>> Johnson
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org 


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: org.odmg.LockNotGrantedException

Posted by Armin Waibel <ar...@apache.org>.
Hi Johnson,

could you please post some (pseudo) code so that I can write a test to
reproduce your locking problem. Is OJB running in a managed (e.g. using
an appServer with JTA) or non-managed environment.

> If I use another session to read it ok,But the record I wrote never
> change.

sounds as the record was not committed.

regards,
Armin


Johnson wrote:
> Hi!
> 
> I try to upgrade my ojb in cocoon from 1.0.1 to 1.0.3.
> when I save a record and then read the record(or others) the system got an error
> org.odmg.LockNotGrantedException
> If I use another session to read it ok,But the record I wrote never change.
> the objectcache I use in 1.0.1 is org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl
> and 1.0.3 I use the same or ObjectCacheTwoLevelImpl it read ok then write no error(but database no record) and then read again and got the error.
> is there something I'm wrong?
> 
> Best Regards
> 
> Johnson

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org