Persistent.find() behavior
Gene McCullough <[email protected]>
| Newsgroups | gmane.comp.java.keel.user |
|---|---|
| Message-ID | <[email protected]> |
myPersistent has an id field, defined as primary key, two other fields,
number and year, defined as int and allow nulls, and some other assorted
fields.
the following code snippet:
PersistentFactory pf =
(PersistentFactory) request.getService(
PersistentFactory.ROLE,
myDB); //request.getDomain()
try {
// This is the actual persistent, see the Appeal entity
Persistent m = pf.create("occa.appeal");
String genemsg = "";
// Set the fields we are interested in
if (
SuperString.notNull(request.getParameterAsString("Year")).equals("")) {
genemsg = genemsg.concat("tried with just id\n");
m.setField("id", request.getParameter("Number"));
} else {
m.setField("number", request.getParameter("Number"));
m.setField("year", request.getParameter("Year"));
}
if( m.find() ){
res.addOutput("found", genemsg.concat("WOOHOO! YOU DA
MAN!!!\nNumber = " + m.getFieldString("number")));
}else{
res.addOutput("found", genemsg.concat("YIKES! =0("));
}
// end snippet
returns YIKES! =0( (meaning false on the find())
and i get this in the svc-persist-default log (same thing if i try with
hibernate actually):
DEBUG 2004-04-16 14:53:41.041 [persist-default]
(/org.keel.services.persist.defaultpersist.DefaultPersistent.retrieve(DefaultPersistent.java:961)): Executing: SELECT id, number, year, [OTHER FIELDS HERE] FROM appeal WHERE id = 10000 AND number = 0 AND year = 0
OR
DEBUG 2004-04-16 14:53:41.041 [persist-default]
(/org.keel.services.persist.defaultpersist.DefaultPersistent.retrieve(DefaultPersistent.java:961)): Executing: SELECT id, number, year, [OTHER FIELDS HERE] FROM appeal WHERE id = 0 AND number = 100 AND year = 2003
depending on which way I try to lookup the object. Please notice it is
attempting to set a value for all three fields, regardless. The javadoc
says that find() trys to lookup based on "current" fields. This is
where I think I'm getting things wrong.
Is this code snippet above not the proper way to look up a persistent?
I've defined them as javabean style POJOs.
if I just set the id of the persistent, and use the following code:
m.retrieve();
res.addOutput("found", m.toString());
i get the object as expected, so I know the db comm is working ok.
Any help appreciated,
gene