Thomas,


I tried your suggestion. I don't know how to interpret the results, though :-). I changed the code fragment to:

========

    PersistenceManagerFactory pmf = new OjbStorePMF();
    PersistenceManager pm = pmf.getPersistenceManager();
    PersistenceBrokerFactory.defaultPersistenceBroker().clearCache();

    pm.currentTransaction().begin();
    Extent extent = pm.getExtent(Building.class, false);
    for (Iterator iterator = extent.iterator();
        iterator.hasNext();)
    {
        Building b = (Building) iterator.next();
    }

pm.currentTransaction().commit();

    Building example = new Building();
    example.setBuildingID(4);
    Identity oid = new Identity(example);
    pm.currentTransaction().begin();

Building building = (Building) pm.getObjectById(oid, false);

========

However, I am still getting the same exception:

========

javax.jdo.JDOUserException: Given object is not a valid OID.
FailedObject:org.lbjnow.calvin.location.Building{4}
NestedThrowables:
java.lang.IllegalArgumentException: arg1
at com.sun.jdori.common.CacheManagerImpl.createNewSM(Unknown Source)
at com.sun.jdori.common.CacheManagerImpl.getStateManager(Unknown Source)
at com.sun.jdori.common.CacheManagerImpl.getObjectById(Unknown Source)
at com.sun.jdori.common.PersistenceManagerImpl.getObjectById(Unknown Source)
at com.sun.jdori.common.PersistenceManagerWrapper.getObjectById(Unknown Source)
at org.apache.jsp.tj_jsp._jspService(tj_jsp.java:143)


========

I haven't had any problems using getObjectById() on objects that have just been persisted (consistent with the root problem), if I remember correctly. Also, as before, when I iterate through the Extent, the objects all return false to jdoIsPersistent(). I also tried pm.getObjectById(new Identity(b)) from within the Extent iteration loop, which threw the same JDOUserException.

I can't tell if this is good news or bad; hopefully this gives you enough information to tell. If nothing else, it's consistent!



Thomas Mahler wrote:

Hi Ketan,

Ketan Gangatirkar wrote:


Thomas,


I tried using the method in tutorial4 to look up objects by OID, but I kept getting "javax.jdo.JDOUserException: Given object is not a valid OID." This is the relevant code section, basically copied out of org.apache.ojb.tutorial5.UCEditProduct and adapted slightly:

========

    PersistenceManagerFactory pmf = new OjbStorePMF();
    PersistenceManager pm = pmf.getPersistenceManager();

    Building example = new Building();
    example.setBuildingID(4);

    Identity oid = new Identity(example);
    pm.currentTransaction().begin();

Building building = (Building) pm.getObjectById(oid, false);

========



Mhh, that's quite strange! that's the virtually the same code as in my UCEdit Example.
I definitely works with the Product class. Do you get the OJB JDO tutorial app running with the UCEdit usecase on your machine?


AFter looking clsoer at the JDORI I have an idea:
The problem could be caused because in my UCEdit the object to lookup is already in the JDORI cache. In your it is not and the cache wants to create a new SM, which then fails.


you could try to load the complete extent of your Building objects and iterate through it before calling your code fragment.
If it works, my assumption is correct, and I have even more work to do :-(


cheers,
Thomas

oid.toString() returns "org.lbjnow.calvin.location.Building{4}" which certainly looks plausible.

As a result, the work-around does not work :-/. This happens with all my objects; I just picked the simplest to demonstrate. The repository_user.xml section is:

========

<class-descriptor class="org.lbjnow.calvin.location.Building"
    table="building">
<field-descriptor id="1" name="buildingID" column="building_id"
    jdbc-type="INTEGER" primarykey="true"  autoincrement="true"
    sequence-name="building_id_seq" />
<field-descriptor id="2" name="shortName" column="short_name"
    jdbc-type="VARCHAR"/>
<field-descriptor id="3" name="longName" column="long_name"
    jdbc-type="VARCHAR"/>
</class-descriptor>

========

The part of the .jdo file for that class is:

========

<class name="Building" identity-type="application"
    objectid-class="java.lang.Integer">
    <field name="buildingID" primary-key="true"
        null-value="exception" />
    <field name="shortName" />
    <field name="longName" />
</class>

========

The class itself is rather simple right now, with just the fields listed above and the appropriate getter/setter methods. The rest of the exception looks like this:

========

javax.jdo.JDOUserException: Given object is not a valid OID.
FailedObject:org.lbjnow.calvin.location.Building{4}
NestedThrowables:
java.lang.IllegalArgumentException: arg1
at com.sun.jdori.common.CacheManagerImpl.createNewSM(Unknown Source)
at com.sun.jdori.common.CacheManagerImpl.getStateManager(Unknown Source)
at com.sun.jdori.common.CacheManagerImpl.getObjectById(Unknown Source)
at com.sun.jdori.common.PersistenceManagerImpl.getObjectById(Unknown Source)
at com.sun.jdori.common.PersistenceManagerWrapper.getObjectById(Unknown Source)
at org.apache.jsp.tj_jsp._jspService(tj_jsp.java:83)


========

If I can get lookups to work this way, that would certainly suffice for my needs.



Thomas Mahler wrote:

Hi again ketan,

Ketan Gangatirkar wrote:


The only problem seems to be that I did not manage to transfer the correct
state information during the retrieval of extents. Only if you rely on this
state information you'll get problems...





Ah, there it is. I have this problem when retrieving objects from JDOQL queries as well as using the methods defined by Extent. Did I misunderstand you?




No, that's what I meant. JDOQL queries rely on extents, that's why.
The tutorial app does only edit objects based on a primary key lookup...





--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to