RES: Update problem

From: Reinaldo Coelho Sartorelli (reinaldo.sartorell..ES.com)
Date: Wed Jan 19 2005 - 14:30:44 EST

  • Next message: Jin Lee: "newbie question: to DepPK"

    Tks Michael, the problem is the DataContext...

    Now is Ok.

    Tks

    -----Mensagem original-----
    De: Gentry, Michael (Contractor) [mailto:michael_gentr..anniemae.com]
    Enviada em: quarta-feira, 19 de janeiro de 2005 17:16
    Para: cayenne-use..bjectstyle.org
    Assunto: RE: Update problem

    Is your "system" object already in a DataContext (in the alterSystem() method)?

    If "system" is already in a DataContext, you don't need to call DataContext.registeredObject(), because it is in your data context already. If "system" is NOT in a DataContext, all of your set methods (setNamSystem(), setSglSystem(), etc) will cause Cayenne to be unaware of those changes, so when you commit, Cayenne thinks they are clean and does nothing.

    I'm not certain, but if "system" is in your DataContext and then you call registeredObject(), I suspect it'll discard all of your changes, but again, I'm not certain of that.

    /dev/mrg

    -----Original Message-----
    From: Reinaldo Coelho Sartorelli [mailto:reinaldo.sartorell..ES.com]
    Sent: Wednesday, January 19, 2005 1:55 PM
    To: cayenne-use..bjectstyle.org
    Subject: RES: Update problem

    Tks Gentry,
            But i have set the values of object in another class, its affect the object to persist?

    Follow the method whith sets:

            public String alterSystem(String nome, String sigla, String apelido, String versao, Short licencas, String nomeLicenca, boolean pacote, boolean codigoFonte){
                    //Cria as variaveis para gravação.
                    FindLicence findLicence = new FindLicence();
                    
                            //Preenche os dados para cadastro.
                            system.setNamSystem(nome);
                            system.setSglSystem(sigla);
                            system.setNamAliasSystem(apelido);
                            system.setDscVersion(versao);
                            system.setQtdLicences(licencas);
                            
                            //Carrega a Licença informada.
                            Licence licence = null;
                            if(nameLicence != null) licenca = findLicence.searchLicence(nameLicence);
                            
                            //Preenche Pacote e Codigo Fonte
                            String strPack = null, strFont = null;
                            if(pack == true) strPack = "Y"; else strPack = "N";
                            if(font == true) strFont = "Y"; else strFont = "N";
                            sistema.setIndPack(strPack);
                            sistema.setIndFont(strFont);
                            
                            //Valida informações informadas.
                            if(system.updateSystem(system) == false) {
                                    String msgErr = new String("Error.");
                                    return msgErr;
                            }
                            return null;
            }

    Tks,
    Reinaldo.

    -----Mensagem original-----
    De: Gentry, Michael (Contractor) [mailto:michael_gentr..anniemae.com]
    Enviada em: quarta-feira, 19 de janeiro de 2005 16:27
    Para: cayenne-use..bjectstyle.org
    Assunto: RE: Update problem

    Well, since you haven't edited the object, I wouldn't expect Cayenne to save anything, even if the original object in the database has "invalid" data. I would expect the validation routines to only be called for objects that have been edited and need to be saved. Also, keep in mind that if an object has a firstName of "frank" and you do a setFirstName("frank") on it, Cayenne is smart enough to know that the object didn't really change and it will not be flagged as dirty/edited, so nothing would be saved to the database on commit.

    Hope that helps!

    /dev/mrg

    -----Original Message-----
    From: Reinaldo Coelho Sartorelli [mailto:reinaldo.sartorell..ES.com]
    Sent: Wednesday, January 19, 2005 1:18 PM
    To: cayenne-use..bjectstyle.org
    Subject: Update problem

    I´ve a update but this update don´t generate error, and don´t commit information, follow my code:

            public boolean updateSystem(Sys system){
                    try{
                            con.registeredObject(system.getObjectId());
                            con.setValidatingObjectsOnCommit(true);
                            con.commitChanges();
                            return true;
                    }
                    catch(Exception e){
                            con.rollbackChanges();
                            return false;
                    }
            }

    Tanks,
    Reinaldo.

    ________________________________________________________________________
    This communication is for use by the intended recipient and contains information that may be privileged, confidential or copyrighted under law. If you are not the intended recipient, you are hereby formally notified that any use, copying or distribution of this e-Mail, in whole or in part, is strictly prohibited. Please notify the sender by return e-Mail and delete this e-Mail from your system. Unless explicitly and conspicuously stated in the subject matter of the above e-Mail, this e-Mail does not constitute a contract offer, a contract amendment, or an acceptance of a contract offer. This e-Mail does not constitute consent to the use of sender's contact information for direct marketing purposes or for transfers of data to third parties.

    This email has been scanned for all viruses by the MessageLabs service.

    ________________________________________________________________________
    This email has been scanned for all viruses by the MessageLabs service.

    ________________________________________________________________________
    This communication is for use by the intended recipient and contains information that may be privileged, confidential or copyrighted under law. If you are not the intended recipient, you are hereby formally notified that any use, copying or distribution of this e-Mail, in whole or in part, is strictly prohibited. Please notify the sender by return e-Mail and delete this e-Mail from your system. Unless explicitly and conspicuously stated in the subject matter of the above e-Mail, this e-Mail does not constitute a contract offer, a contract amendment, or an acceptance of a contract offer. This e-Mail does not constitute consent to the use of sender's contact information for direct marketing purposes or for transfers of data to third parties.

    This email has been scanned for all viruses by the MessageLabs service.

    ________________________________________________________________________
    This email has been scanned for all viruses by the MessageLabs service.

    ________________________________________________________________________
    This communication is for use by the intended recipient and contains information that may be privileged, confidential or copyrighted under law. If you are not the intended recipient, you are hereby formally notified that any use, copying or distribution of this e-Mail, in whole or in part, is strictly prohibited. Please notify the sender by return e-Mail and delete this e-Mail from your system. Unless explicitly and conspicuously stated in the subject matter of the above e-Mail, this e-Mail does not constitute a contract offer, a contract amendment, or an acceptance of a contract offer. This e-Mail does not constitute consent to the use of sender's contact information for direct marketing purposes or for transfers of data to third parties.

    This email has been scanned for all viruses by the MessageLabs service.



    This archive was generated by hypermail 2.0.0 : Wed Jan 19 2005 - 14:30:42 EST