1 2 Previous Next 18 Replies Latest reply on Aug 18, 2002 4:29 PM by Denis Pasek

    CMR Fields not being persisted

    Marcus Brito Novice

      I've got a problem with JBossCMP (jboss3.0.0-beta). Apparently, CMR fields are not being persisted.

      Here is my situation: I got a bean with lots of CMP fields and a couple of CMR fields. The ejbCreate() methods takes as arguments most of CMP field values AND the CMR beans values. Here's the declaration:

       public String ejbCreate(String numero, String tipo, AgenteLocal agente,
       ClienteLocal cliente, String numeroPedido, Date dataPedido,
       Date dataEntregaPrevista, String frete)
       throws CreateException
      

      ClienteLocal and AgenteLocal will be stored in CMR fields. In ejbCreate() I call setXXX() for all CMP fields. In ejbPostCreate() I call setAgente(agente) and setCliente(cliente). The bean is created without error.

      Later, when I find() the bean I created and calls getAgente() or getCliente() on it, both methods return null. Looking at the database, the foreign key fields are set to null, not to the correct values. What's happening?

      Attached goes the complete source to this entity bean. Please, I'd appreciate any help.

        • 1. Re: CMR Fields not being persisted
          Dain Sundstrom Master

          Check the log (you will need to turn on debug for org.jboss.ejb.plugins.cmp). For your create you should see a find for the new pk followed by an insert with all columns set except of the cmr fields. Almost imedately after that you should see an update of the inserted row with cmr fields set. Are you getting the update command?

          • 2. Re: CMR Fields not being persisted
            Marcus Brito Novice

            No, I'm not getting the update command. Here is the portion of the logfile that correspond to the bean insertion:

            2002-02-27 13:33:37,566 [AutorizacaoFornecimento] Create: pk=8780808080808080
            2002-02-27 13:33:37,566 [AutorizacaoFornecimento] Executing SQL: SELECT COUNT(*) FROM af WHERE af_id=?
            2002-02-27 13:33:37,573 [AutorizacaoFornecimento] Executing SQL: INSERT INTO af (af_id, af_numero, af_finalizada, af_pedido, af_tipo, af_data_preenchimento, af_data_pedido, af_data_prevista, af_data_entrega, af_transporte, af_total_material, af_total_servico, af_valor_cat, af_pagamento_desc, af_pagamento_tipo, af_setor, af_sistema, af_nu_ramais_analogico, af_nu_ramais_digitais, af_nu_canais, af_nu_pa, af_nu_supervisao, af_nu_stack, af_clie_id, af_agen_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
            2002-02-27 13:33:37,658 [AutorizacaoFornecimento] Create: Rows affected = 1


            Just after this, I got more logging from ejbPostCreate. Please note that there are some log statements from my class here.

            2002-02-27 13:33:37,826 [AutorizacaoFornecimentoEJB] Em ejbPostCreate(...)
            2002-02-27 13:33:37,828 [AutorizacaoFornecimentoEJB] agenteId: 2
            2002-02-27 13:33:37,828 [AutorizacaoFornecimentoEJB] clienteId: 28982
            2002-02-27 13:33:37,832 [Agente] Executing SQL: SELECT af_agen_id, af_id FROM af WHERE (af_agen_id=?) OR (af_agen_id=?) OR (af_agen_id=?) OR (af_agen_id=?) OR (af_agen_id=?) OR (af_agen_id=?) OR (af_agen_id=?) OR (af_agen_id=?) OR (af_agen_id=?) OR (af_agen_id=?) OR (af_agen_id=?) OR (af_agen_id=?) OR (af_agen_id=?) OR (af_agen_id=?) OR (af_agen_id=?) OR (af_agen_id=?) OR (af_agen_id=?) OR (af_agen_id=?) OR (af_agen_id=?) OR (af_agen_id=?) OR (af_agen_id=?) OR (af_agen_id=?)
            2002-02-27 13:33:37,841 [Cliente] Executing SQL: SELECT af_clie_id, af_id FROM af WHERE (af_clie_id=?) OR (af_clie_id=?) OR (af_clie_id=?) OR (af_clie_id=?) OR (af_clie_id=?) OR (af_clie_id=?) OR (af_clie_id=?) OR (af_clie_id=?) OR (af_clie_id=?) OR (af_clie_id=?) OR (af_clie_id=?) OR (af_clie_id=?) OR (af_clie_id=?) OR (af_clie_id=?) OR (af_clie_id=?) OR (af_clie_id=?) OR (af_clie_id=?) OR (af_clie_id=?) OR (af_clie_id=?)
            2002-02-27 13:33:37,847 [AutorizacaoFornecimentoEJB] agenteId (após set): 2
            2002-02-27 13:33:37,848 [AutorizacaoFornecimentoEJB] clienteId (após set): 28982

            If you look at the attached source you'll see that in ejbPostCreate() I log the id's from the AgenteLocal and ClienteLocal parameters received, set them both with setAgente() and setCliente() and then log the output from getAgente().getId() and getCliente().getId(). According to the log, the CMR fields were set. However, they are never updated to the database. The update never comes.

            Note: this log excerpt is from jboss-3.0.0beta2, checked out from CVS just a minute ago. The log output from jboss-3.0.0beta was a lot more verbose.

            • 3. Re: CMR Fields not being persisted
              Marcus Brito Novice

              I've tried the 3.0.0 beta and the latest CVS tip and the problem is still the same. There is no update after ejbPostCreate().

              Someone please help me :(

              • 4. Re: CMR Fields not being persisted
                David Jencks Master

                Dain, is your code doing the expected update or are you expecting an ejbStore triggered by the end of a transaction to do it? If the latter, possibly the quadratic algorithm fix I did is preventing ejbStore from being called. Let me know. I was assuming that after ejbCreate the bean was synchronized with the db and "clean".

                • 5. Re: CMR Fields not being persisted
                  Dain Sundstrom Master

                  > Dain, is your code doing the expected update or are
                  > you expecting an ejbStore triggered by the end of a
                  > transaction to do it?

                  This is supposed to be triggered by the tx complete.

                  > If the latter, possibly the
                  > quadratic algorithm fix I did is preventing ejbStore
                  > from being called. Let me know. I was assuming that
                  > after ejbCreate the bean was synchronized with the db
                  > and "clean".

                  I was thinking the same thing. When a bean comes back from the ejbCreate/ejbPostCreate call it can be dirty. Can you add this to the dirty list after create?

                  • 6. Re: CMR Fields not being persisted
                    Marcus Brito Novice

                    David, please write here when the fix is landed. Meanwhile, there is a way to work around this?

                    • 7. Re: CMR Fields not being persisted
                      Marcus Brito Novice

                      Good news. I tried to venture alone into JBoss source code and apparently solved the bug. Just added a call to storeEntity() in CMPPersistenceManager.java after it calls ejbPostCreate().

                      I submited the small patch to sourceforge. Here is the link to the tracker item: https://sourceforge.net/tracker/index.php?func=detail&aid=524170&group_id=22866&atid=376687

                      This is the first time I ever dared to look at JBoss source code. Perhaps (probably) what I did is dangerous, stupid or harmful in one way or another. Anyway, I got my problem solved and my heart is still beating fast from the thrill of venturing into this great unknown land of source code :)

                      • 8. Re: CMR Fields not being persisted
                        David Jencks Master

                        It's still a thrill;-)

                        Ensuring that some "store" is called after ejbPostCreate is certainly necessary to fix this problem.

                        I solved it a different way, by adding all new entities to the list of entities that need ejbStore called on them before the end of the transaction (this list is in GlobalTxEntityMap). This code is in EntitySynchronizationInterceptor, which is not persistence-manager specific. My change solves the problem for all possible persistence managers: I believe yours solves it only for the particular cmp2 persistence manager.

                        Anyway, thanks for the patch and please continue to contribute!

                        • 9. Re: CMR Fields not being persisted
                          ppetit Newbie

                          David, where can I get your patch ?
                          regards
                          Philippe

                          • 10. Re: CMR Fields not being persisted
                            Dain Sundstrom Master

                            It is not a patch; it's in cvs HEAD. Download the source from cvs and rebuild.

                            • 11. Re: CMR Fields not being persisted
                              Marcus Brito Novice

                              Thanks for the explanation, David. I know my solution was naive -- I don't know anything about JBoss internal to do something real good. But I hope to know more and more each day :)

                              • 12. Re: CMR Fields not being persisted
                                Roland Chan Newbie

                                I am having this problem with the latest 3.0 release. That is, I am not seeing the UPDATE statement in my server log.

                                In my post create I have a setter

                                setCompany(companyLocal);

                                However, this appears to be ignored. One way I am currently getting around this is to simply add the object to collection on the many side of the relationship.

                                Can anyone suggest anything? I'd be glad to provide additional information, although my thought is it may be something simple...

                                Thanks,
                                RC

                                • 13. Re: CMR Fields not being persisted
                                  Dain Sundstrom Master

                                  This should be fixed in the 3.0.1 final release (today or tomorrow). If the final 3.0.1 release does not fix this, please post a bug report with a test case at sourceforge.

                                  • 14. Re: CMR Fields not being persisted
                                    Roland Chan Newbie

                                    Thanks, Dain. I see that 3.0.1 was released yesterday. Can I assume that this is the release you are referring to? Also, do you know when a 3.0.1/Catalina final will be available?

                                    Thanks again,
                                    RC

                                    1 2 Previous Next