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 Ajitesh Das <aj...@sbcglobal.net> on 2003/07/08 11:12:12 UTC

OJB 1.0 r3:Tutorial 1 : PersistentFieldClass and PersistentFieldDefaultImpl bug/Issue

If I have understood correctly, this PersistentFieldDefaultImpl uses java
bean introspection
to determine the accessors and mutators.
Here are steps I did:
My persistable Test object contains following properties :
            int id;
            int age;
            int height;
Here is the snap shot of my Test table in DB:
        id       age     height
        1        12      134
        2        17      166
        3        22      190
My OJB.properties: I am using
PersistentFieldClass=org.apache.ojb.broker.metadata.fieldaccess.PersistentFi
eldPropertyImpl

I would like to retrieve obj with id = 2, so I wrote following code :
    Test example = new Test();
    example.setId(2);
    Query query = new QueryByCriteria(example);
    broker.beginTransaction();
    Test toBeEdited = (Test) broker.getObjectByQuery(query);
And I am getting NULL.<<<huh>>>
If I change the DB Table with
        id       age     height
        1        12      134
        2        0      0
        3        22      190
I am getting/able to retrieve the obj with id = 2.

I have realized that broker.getObjectByQuery() is issueing SQL
as SELECT * FROM TEST WHERE ID=2 & AGE=0 & HEIGHT=0;
[ please note, in the code, I have only set the ID similar to the TUTORIAL 1
update Product code ]

Where as I am expecting SQL like
SELECT * FROM TEST WHERE ID=2;
[ since I have only set the ID and NOTHING else]

Am I expecting something wrong ?
Or this is a OJB bug in  PersistentFieldDefaultImpl  code.

thanks
aj


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


Re: OJB 1.0 r3:Tutorial 1 : PersistentFieldClass and PersistentFieldDefaultImpl bug/Issue

Posted by kr...@webit.de.
Hi,

please see comment below.

On Tue, Jul 08, 2003 at 02:12:12AM -0700, Ajitesh Das wrote:
> If I have understood correctly, this PersistentFieldDefaultImpl uses java
> bean introspection
> to determine the accessors and mutators.
> Here are steps I did:
> My persistable Test object contains following properties :
>             int id;
>             int age;
>             int height;
> Here is the snap shot of my Test table in DB:
>         id       age     height
>         1        12      134
>         2        17      166
>         3        22      190
> My OJB.properties: I am using
> PersistentFieldClass=org.apache.ojb.broker.metadata.fieldaccess.PersistentFi
> eldPropertyImpl
> 
> I would like to retrieve obj with id = 2, so I wrote following code :
>     Test example = new Test();
>     example.setId(2);
>     Query query = new QueryByCriteria(example);
>     broker.beginTransaction();
>     Test toBeEdited = (Test) broker.getObjectByQuery(query);
> And I am getting NULL.<<<huh>>>
> If I change the DB Table with
>         id       age     height
>         1        12      134
>         2        0      0
>         3        22      190
> I am getting/able to retrieve the obj with id = 2.
> 
> I have realized that broker.getObjectByQuery() is issueing SQL
> as SELECT * FROM TEST WHERE ID=2 & AGE=0 & HEIGHT=0;
> [ please note, in the code, I have only set the ID similar to the TUTORIAL 1
> update Product code ]
> 
> Where as I am expecting SQL like
> SELECT * FROM TEST WHERE ID=2;
> [ since I have only set the ID and NOTHING else]

Imho there is no way for OJB to know whether you set the age an height
fields or not, since global primitives per definition are initialized 
to value 0. I think using Integers instead of int's should fix the
problem, with age==null and height==null they should be ignored when the
statement is generated.


hth,
Jens

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