Hi Jair,

ODMG transaction write to the db only on tx.commit.
Thus q is not persistent in the database when you perform the first query!

All queries (also ODMG OQL!) are executed against the database. So it's obvious that loaded != q after your query.

after commiting the transaction q is stored in the DB and the second query does find it.

Works as designed.

-Thomas

Jair da Silva Ferreira J�nior wrote:
Hi,
    I am using ojb1.0_rc4, ODMG api with OJB queries and mysql4. The problem is that 
when I persist an object and run a identity query looking for the persisted objet the 
query returns null. This only happens when I persist the object and execute the query 
in the same transaction. Is this behaviour correct or is this a bug?
    I added some example code in the end of this email for better understanding.
    Thanks for your help.

Sincerely,
    Jair Jr

Example code:

void doSomething(){
Transaction t=implementation.newTransaction();
t.begin();
Question q=new Question();
t.lock(q,t.WRITE);
q.setStatement("a statement");
q.setNumber(10);
q.setSubject(Subject.PHYSICS);
q.setCorrectAlternative(Alternative.A);
Question example=new Question();
example.setId(q.getId());
QueryByIdentity query=new QueryByIdentity(example);
Question loaded=(Question) ((HasBroker)t).getBroker().getObjectByQuery(query);
//loaded==null !!! why? Shouldn't it be: loaded==q?
t.commit();
t=implementation.newTransaction();
t.begin();
query=new QueryByIdentity(example);
loaded=(Question) ((HasBroker)t).getBroker().getObjectByQuery(query);
//loaded!=null now! loaded==q!
t.commit();
}


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



Reply via email to