>From my experience queryByExample only works with the primary key field(s).
You need to use queryByCriteria to access using any other field.
<Sylvain.Thevoz@swi
sscom.com> To: <[EMAIL PROTECTED]>
cc:
11/12/2002 23:37 Subject: [PB] how to retrieve one
entry
Please respond to
"OJB Users List"
Hello,
I have a class like:
class Workstation {
int workstationID
String workstationName
...
}
The workstation attribute is the primary key (autoincrement=true).
I want to enter the workstationName and retrieve the corresponding entry.
If I try this:
----code
Workstation workstation = new Workstation();
workstation.setWorkstationName("Test");
Query query = new QueryByExample(workstation);
try {
broker.beginTransaction();
Workstation toBeEdited = (Workstation) broker.getObjectByQuery(query);
broker.commitTransaction();
} catch (Throwable t) {
broker.abortTransaction();
t.printStackTrace();
}
----code
This code doesn't work because OJB create a new primary key for this
instance and try to find it in the database. Of course it doesn't find it
and the query return a null value.
It seems that the only way to retrieve one entry is by the workstationID.
Is it right?
Is there other method to do this?
Thank you
Sylvain
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>