Here it's a java thing.
When you initialize your Object Test() its int fields will be instantiated with their
default value, in your code 0.
If you want to retrieve your record with id 2, I suggest you use a
Criteria.addEqualTo() method.
Criteria criteria = new Criteria();
criteria.addEqualTo("id", new Integer(2));
QueryByCriteria query = new QueryByCriteria(Test.class, criteria);
then you can retrieve your object with the broker.
Christophe
Message du 08/07/03 11:12
De : Ajitesh Das
A : [EMAIL PROTECTED]
Copie � :
Objet : 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.<<>>
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]