Hi, > -----Original Message----- > From: Ajitesh Das [mailto:[EMAIL PROTECTED] > Sent: Tuesday, July 08, 2003 11:12 AM > To: [EMAIL PROTECTED] > Subject: 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. No! PersistentFieldDefault impl does not use JavaBeans introspection!
> 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.fieldacces > s.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 ? Yes! new QueryByCriteria(example) produces a query that takes *all* non null values of the object to generate the query. (from the JavaDocs: public QueryByCriteria(java.lang.Object anObject) Build a Query based on anObject all non null values are used as EqualToCriteria ) If you want tbuild queries that only use the primary key columns you should use: new QueryByIdentity(example); cheers, Thomas > Or this is a OJB bug in PersistentFieldDefaultImpl code. > > thanks > aj > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > >
