Will do ... I didn't realize that the problem is with OQL queries that do not 
query by the id. Maybe I should have read the thread more carefully, though .. 
;-).

Werner

On Wed, 10 Nov 2004 13:42:48 +0100, Ralf Joachim wrote:

>
>I recognized this problem too some time ago but didn't analyse as deep 
>as Silvie because I had the identity available.
>
>Could you try the query:
>select account from testXXX.Account account where description = "account 10"
>
>Regards
>Ralf
>
>Werner Guttmann schrieb:
>> Sylvie,
>> 
>> I've just run a couple of tests trying to create an object and load it again 
>> using both Database.load() and OQLQuery.execute() ... and I don't have an 
>> problems.  Here's a code fragment I used in one of the tests:
>> 
>>      public void testQueryAccountCreatedWithinTransaction() throws Exception 
>> {
>>              Account account = null;
>> 
>>              Database db = jdo.getDatabase();
>> 
>>              db.begin();
>>              account = new Account();
>>              account.setId (new Integer (10));
>>              account.setDescription("account 10");
>>              db.create(account);
>>              
>>              OQLQuery query = db.getOQLQuery("select account from 
>> testXXX.Account account where id = 10");
>>              QueryResults results = query.execute();
>>              assertTrue (results.hasMore());
>>              if (results.hasMore()) {
>>                      account = (Account) results.next();
>>                      assertNotNull (account);
>>                      assertEquals (new Integer(10), account.getId());
>>                      assertEquals ("account 10", account.getDescription());
>>              }
>>              db.commit();
>> 
>>              db.begin();
>>              account = (Account) db.load (Account.class, new Integer (10));
>>              db.remove (account);
>>              db.commit();
>> 
>>              db.close();
>>      }
>> 
>> As you can see, I am creating a new Account instance (id 10), and use a 
>> OQLQuery to obtain the very same object again.  
>> 
>> If that little code fragment does not mimick what you are doing, let me know 
>> where the difference is.
>> 
>> Regards
>> Werner
>> 
>> On Tue, 09 Nov 2004 19:01:35 +0100, SYLVIE PALLUEL wrote:
>> 
>> 
>>>I have only one transaction to do everything. So I shouldn't have pb with
>>>transaction isolation.
>>>
>>>After having read your answer, I've made new tests.
>>>
>>>While using a database which supports rollback, I can do this in the same
>>>transaction:
>>>. create an object A
>>>. read back the object A with a pass-thru OQL query 
>>>. read back the object A with a db.load(...,objetA.getId())
>>>. apply the rollback
>>>
>>>I can't :
>>>. read back the object A with a OQL query 
>>>
>>>And If I have two different transactions before the rollback, I can't read
>>>(anyway I use) in my transaction #2 the object being created in my
>>>transaction #1. So the transaction isolation is ok.
>>>
>>>I think there's really something wrong with the way the OQL query is
>>>executed in this case.
>>>Is there something new on this point with the future version?
>>>
>>>The same tests made using direct access by jdbc are ok.
>>>
>>>Thanks for your interest.
>>>
>>>Sylvie.  
>>>
>>>P.S.:
>>>I can't commit the create before trying to access the object in OQL, because
>>>I must rollback everything from the beginning, if there's anything wrong
>>>during the whole operation.
>>>
>>>I tried to explain to the developers that it should be better to store the
>>>id in a variable somewhere and access later when trying to load it (rather
>>>than through a query, OQL or otherwise)... But they just see the fact that
>>>it must work like simple jdbc way ... 
>>>
>>>
>>>___________________
>>>CREDI RA
>>>Sylvie Palluel
>>>
>>>[EMAIL PROTECTED]
>>>___________________
>>>
>>>-----Message d'origine-----
>>>De : Patrick van Kann [mailto:[EMAIL PROTECTED] 
>>>Envoyé : mardi 9 novembre 2004 18:06
>>>À : SYLVIE PALLUEL
>>>Objet : RE: RE : RE : [castor-dev] [jdo] Reading, in the same transaction, a
>>>data just created (reading via oql query)
>>>
>>>In that case, I think Castor OQL is behaving correctly with respect to
>>>transaction isolation.
>>>MySQL without Innodb simply doesn't support transactions, hence the data is
>>>written regardless of whether you call db.commit().
>>>In order to guarantee that your transaction is isolated, queries should not
>>>have access to the data in the database until it commits for the reason I
>>>stated earlier. If your application uses JDBC or pass-through to load an
>>>object that could become unavailable due a rollback, your app would be in an
>>>inconsistent state.
>>>
>>>I think you should consider re-designing your application so that you either
>>>commit the create before trying to access the object in OQL, or you need to
>>>store the id in a variable somewhere that you can access later when trying
>>>to load it (rather than through a query, OQL or otherwise).
>>>
>>>In any case, surely OQL is an unreliable way to retrieve an object? What if
>>>you had to results that matched your criteria?
>>>
>>>I hope this helps,
>>>
>>>Patrick
>>>
>>>-----Original Message-----
>>>From: SYLVIE PALLUEL [mailto:[EMAIL PROTECTED]
>>>Sent: Tue 11/9/2004 4:28 PM
>>>To: Patrick van Kann
>>>Subject: RE : RE : [castor-dev] [jdo] Reading,  in the same transaction, a
>>>data  just created (reading via oql query)
>>>
>>>Yes, I can confirm that when I rollback the transaction, the new data is not
>>>created in my database (which way I use to test).
>>>
>>>
>>>
>>>For information, I have the problem with MySql Innodb (supports rollback)
>>>and Oracle.
>>>
>>>With MySql Isam (no rollback), the program was ok, that means that the Oql
>>>query brings back the new Object ..
>>>
>>>
>>>
>>>In fact it seems that the Oql query tries to retrieve the object from the
>>>database, and is not looking at his cache .
>>>
>>>
>>>
>>>Sylvie.
>>>
>>>___________________
>>>
>>>CREDI RA
>>>
>>>Sylvie Palluel
>>>
>>>
>>>
>>>[EMAIL PROTECTED]
>>>
>>>___________________
>>>
>>>
>>>
>>>-----Message d'origine-----
>>>De : Patrick van Kann [mailto:[EMAIL PROTECTED]
>>>Envoyé : mardi 9 novembre 2004 16:46
>>>À : SYLVIE PALLUEL
>>>Objet : RE: RE : [castor-dev] [jdo] Reading, in the same transaction, a data
>>>just created (reading via oql query)
>>>
>>>
>>>
>>>I must admit I am surprised that this is the behaviour you are seeing. I
>>>would have thought that the data would not be written to the database until
>>>the commit phase, otherwise you risk dirty reads (for example if the castor
>>>transaction later rolls back after your JDBC call has accessed the data).
>>>
>>>Can you confirm that when you rollback the transaction (instead of
>>>committing) that the data in the database is removed after the rollback(i.e.
>>>not available to either JDBC or OQL pass through)?
>>>
>>>Patrick
>>>
>>>
>>>-----Original Message-----
>>>From: SYLVIE PALLUEL [mailto:[EMAIL PROTECTED]
>>>Sent: Tue 11/9/2004 3:09 PM
>>>To: [EMAIL PROTECTED]
>>>Subject: RE : [castor-dev] [jdo] Reading,  in the same transaction, a data
>>>just created (reading via oql query)
>>>
>>>
>>>I don't know if this can help you, but I made another test with an OQL
>>>pass-thru, and I get the new object before the commit phase.
>>>
>>>Is there something special to do to enable the OQL query to see the objects
>>>created inside the current transaction?
>>>
>>>Sylvie.
>>>
>>>___________________
>>>CREDI RA
>>>Sylvie Palluel
>>>
>>>[EMAIL PROTECTED]
>>>___________________
>>>
>>>
>>>
>>>>-----Message d'origine-----
>>>>De : SYLVIE PALLUEL [mailto:[EMAIL PROTECTED]
>>>>Envoyé : mardi 9 novembre 2004 15:26
>>>>À : [EMAIL PROTECTED]
>>>>Objet : Re: [castor-dev] [jdo] Reading, in the same transaction, a data
>>>>just created (reading via oql query)
>>>>
>>>>Hello Patrick,
>>>>
>>>>As I answered to Marco, if my example is simple, the real code is not so
>>>>simple!
>>>>
>>>>The program - which is running alone - tries to upgrade the content of a
>>>>database which contents application parameters (a new version of the
>>>>application will bring many new objects in different "tables", and
>>>>modification in some existing objects).
>>>>
>>>>The process may be long, and in fact when we need to read the object, we
>>>>have not anymore the object's reference: we have only keywords to retrieve
>>>>it from database by an oql query.
>>>>
>>>>If, in the example, I use directly jdbc, and not jdo, the query retrieves
>>>>the new object.
>>>>
>>>>You said OQL doesn't go through the cache: that what I thought first, but
>>>>if
>>>>I try the same thing while modifying an existing object, my oql query
>>>>retrieves the modified object!
>>>>
>>>>
>>>>db.begin();
>>>>log.info("Object read via oql ");
>>>>ArrayList lesDossiers = RequetesJdoAssure.getLesDossiers("GALO", "%", "%",
>>>>"%", db);
>>>>for (Iterator iter = lesDossiers.iterator(); iter.hasNext();) {
>>>>      Dossier element = (Dossier) iter.next();
>>>>      log.info(" Nom = " + element.getNomPatronymique() + " - Prénom = " +
>>>>element.getPrenom());
>>>>      log.info(" Modif du prénom");
>>>>      // The object is modified
>>>>      element.setPrenom("TOTO");
>>>>}
>>>>
>>>>
>>>>log.info(" Object is read again via oql ");
>>>>lesDossiers = RequetesJdoAssure.getLesDossiers("GALO", "%", "%", "%", db);
>>>>for (Iterator iter = lesDossiers.iterator(); iter.hasNext();) {
>>>>              Dossier elementModifie = (Dossier) iter.next();
>>>>              log.info(" Nom Apres modif = " +
>>>>elementModifie.getNomPatronymique() + " - Prénom après modif = " +
>>>>elementModifie.getPrenom());
>>>>}
>>>>
>>>>
>>>>So I'm little lost !
>>>>
>>>>
>>>>Sylvie.
>>>>
>>>>___________________
>>>>CREDI RA
>>>>Sylvie Palluel
>>>>
>>>>[EMAIL PROTECTED]
>>>>___________________
>>>>
>>>>
>>>>
>>>>>-----Message d'origine-----
>>>>>De : Patrick van Kann [mailto:[EMAIL PROTECTED]
>>>>>Envoyé : mardi 9 novembre 2004 14:19
>>>>>À : [EMAIL PROTECTED]
>>>>>Objet : RE: [castor-dev] [jdo] Reading, in the same transaction, a data
>>>>>just created (reading via oql query)
>>>>>
>>>>>Sylvie,
>>>>>
>>>>>Your object won't be in the database until you call commit. Because OQL
>>>>>doesn't go through the cache, it won't find anything unless it is in the
>>>>>database.
>>>>>
>>>>>Why do you no longer have the ID? Surely you can get this from the
>>>>
>>>>object
>>>>
>>>>>after create()?
>>>>>
>>>>>Cheers,
>>>>>
>>>>>Patrick
>>>>>
>>>>>
>>>>>-----Original Message-----
>>>>>From: SYLVIE PALLUEL [mailto:[EMAIL PROTECTED]
>>>>>Sent: Tue 11/9/2004 12:43 PM
>>>>>To: [EMAIL PROTECTED]
>>>>>Subject: [castor-dev] [jdo] Reading,  in the same transaction, a data
>>>>>just created (reading via oql query)
>>>>>
>>>>>Sorry!
>>>>>Here's the complete message ...
>>>>>
>>>>>Hi,
>>>>>
>>>>>In a transaction (between the db.begin() and the db.commit()), I'm
>>>>>creating
>>>>>a new object A .
>>>>>And then, far away in the code, but in the same transaction, I need to
>>>>>read
>>>>>again the object A to create another object B.
>>>>>To do this, as I have no longer the id, I'm usinq an oql query to
>>>>
>>>>retrieve
>>>>
>>>>>A... But it is not found...
>>>>>What can I do (castor configuration or special command) to be able to
>>>>
>>>>read
>>>>
>>>>>it by an oql query ?
>>>>>
>>>>>
>>>>>db.begin();
>>>>>
>>>>>log.info(" Creating object dossier via jdo ");
>>>>>Dossier dossierAjoute = new Dossier();
>>>>>dossierAjoute.setNomPatronymique("LEGRAND");
>>>>>dossierAjoute.setPrenom("ALEXANDRE");
>>>>>dossierAjoute.setCivilite("M");
>>>>>dossierAjoute.setNumNatident("11111111111");
>>>>>
>>>>>db.create(dossierAjoute);
>>>>>
>>>>>
>>>>>log.info(" Reading back the object just created via jdo "); lesDossiers
>>>>
>>>>=
>>>>
>>>>>RequetesJdoAssure.getLesDossiers("LEGRAND", "%", "ALEXANDRE", "%", db);
>>>>>log.info(" Nbre de dossiers = " + lesDossiers.size()); // The result
>>>>
>>>>will
>>>>
>>>>>be
>>>>>0 ... for (Iterator iter = lesDossiers.iterator(); iter.hasNext();) {
>>>>>    Dossier element = (Dossier) iter.next();
>>>>>    log.info(" Nom Apres creation = " + element.getNomPatronymique() + "
>>>>>- Prénom après creation = " + element.getPrenom()); }
>>>>>
>>>>>// if I had the object if I could do this ..
>>>>>log.info(" Reading back the object by db.load() ");
>>>>>Dossier dossier=(Dossier)
>>>>>db.load(Class.forName("fr.cnam.scapin.metier.donnees.dossiers.Dossier"),
>>>>>new
>>>>>Integer(dossierAjoute.getIdDossier()));
>>>>>// this will be ok
>>>>>log.info("Dossier relu par db.load " + dossier.toString());
>>>>>
>>>>>db.rollback();
>>>>>
>>>>>
>>>>>
>>>>>Thanks for your help.
>>>>>
>>>>>Sylvie
>>>>>___________________
>>>>>CREDI RA
>>>>>Sylvie Palluel
>>>>>
>>>>>[EMAIL PROTECTED]
>>>>>___________________
>>>>>
>>>>>
>>>>>
>>>>>>-----Message d'origine-----
>>>>>>De : SYLVIE PALLUEL [mailto:[EMAIL PROTECTED]
>>>>>>Envoyé : mardi 9 novembre 2004 13:23
>>>>>>À : [EMAIL PROTECTED]
>>>>>>Objet : [castor-dev] [castor-user][jdo] Reading, in the same
>>>>>
>>>>>transaction,
>>>>>
>>>>>>a data just created (reading via oql query)
>>>>>>
>>>>>>Hi,
>>>>>>
>>>>>>In a transaction (between the db.begin() and the db.commit()), I'm
>>>>>>creating
>>>>>>a new object A .
>>>>>>And then, far away in the code, but in the same transaction, I need to
>>>>>>read
>>>>>>again the object A to create another object B .
>>>>>>To do this, as I have no longer the id, I'm usinq an oql query to
>>>>>
>>>>>retrieve
>>>>>
>>>>>>A... But it is not found...
>>>>>>What can I do (castor configuration or special command) to be able to
>>>>>
>>>>>read
>>>>>
>>>>>>it by an oql query ?
>>>>>>
>>>>>> .
>>>>>
>>>
>>>
>>>
>>>
>> 
>> 
>> ------------------------------------------------------------------------
>> 
>> ----------------------------------------------------------- 
>> If you wish to unsubscribe from this mailing, send mail to
>> [EMAIL PROTECTED] with a subject of:
>>         unsubscribe castor-dev
>
>-- 
>
>Syscon Ingenieurbüro für
>Meß- und Datentechnik GmbH
>Ralf Joachim
>Raiffeisenstraße 11
>D-72127 Kusterdingen
>Germany
>
>Tel.   +49 7071 3690 52
>Mobil: +49 173 9630135
>Fax    +49 7071 3690 98
>
>Email: [EMAIL PROTECTED]
>Web:   www.syscon-world.de
>
>
>
>----------------------------------------------------------- 
>If you wish to unsubscribe from this mailing, send mail to
>[EMAIL PROTECTED] with a subject of:
>        unsubscribe castor-dev
>

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to