QueryByCriteria(example) build a query based on _all_ non-null instvars of the example object whereas QueryByIdentity(example) uses the pk-values only.
hth jakob
Emil Alexandrov wrote:
Hi I'm new in using OJB and so far I just try to follow the examples in
tutorials.
I'm using OJB 1.0.rc3 and MySQL DB.
In my code which is copied and modified a little from tutorial1.html
section - Deleting Object I noticed the following problem.
When I use Query query = new QueryByCriteria(example);
to create query which will return the object that I want to delete
nothing happens.
But if I use Query query = new QueryByIdentity(example);
The record is found and successfully deleted.
In the example in tutorial1.html QueryByCriteria is used.
Can someone explain what I do wrong? And is there a way to see what SQL
statement is generated in both cases? Here is the complete code I'm using:
public void deleteUser(int userID) {
PersistenceBroker broker = null;
UserData example = new UserData();
example.setUserID(userID);
// 2. build a QueryByCriteria from this sample instance:
Query query = new QueryByCriteria(example);
try
{
broker =
PersistenceBrokerFactory.defaultPersistenceBroker();
// start broker transaction broker.beginTransaction(); // lookup the product specified by the QBE UserData toBeDeleted = (UserData) broker.getObjectByQuery(query); // now ask broker to delete the object broker.delete(toBeDeleted); // commit transaction broker.commitTransaction(); } catch (Throwable t) { // rollback in case of errors broker.abortTransaction(); t.printStackTrace(); } }
10x Emil
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
