Thank you Johan.
I have not found this in Tutorials (Tutorial 1).

Regards
Sylvain

-----Message d'origine-----
De: Johan Neidenmark [mailto:[EMAIL PROTECTED]]
Date: mercredi, 11. d�cembre 2002 14:09
�: 'OJB Users List'
Objet: SV: [PB] how to retrieve one entry


Criteria crit = new Criteria();
crit.addEqualTo("workstationName", "Test");
Query query = new QueryByCriteria(Workstation.class, crit, true); //
true to get distinct, just in case
Workstation toBeEdited = (Workstation) broker.getObjectByQuery(query);

Is one way to do it..

/Johan

-----Ursprungligt meddelande-----
Fr�n: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] 
Skickat: den 11 december 2002 13:38
Till: [EMAIL PROTECTED]
�mne: [PB] how to retrieve one entry


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]>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to