7 Replies Latest reply on Jan 31, 2003 12:07 AM by prabhakar

    CMP Update problem

    Dave Newbie

      Hi,

      What I have is the following:
      a unidirectional 1-1 relation between 2 entity beans
      Article 1 ----> 1 Language
      they are both Local entity beans

      When I try to update changes made to my article and language, I receive an error. I do the following to update:
      input are article id, article attributes and language id
      I lookup the article (findByPrimaryKey). Next, I update the article attributes (calling the setters).
      Then, to update the language, I lookup the language (also findByPrimaryKey) and try to update the language (article.setLanguage(found_language))
      If I do this last action, I retrieve the next error :

      15:00:26,489 ERROR [LogInterceptor] TransactionRolledbackException, causedBy:
      javax.ejb.EJBException: Preload data contains multiple values, but this cmr field is single valued
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.load(JDBCCMRFieldBridge.java:893)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.removeRelation(JDBCCMRFieldBridge.java:855)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.removeRelation(JDBCCMRFieldBridge.java:836)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCRelationInterceptor.invoke(JDBCRelationInterceptor.java:176)
      at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invoke(EntitySynchronizationInterceptor.java:340)
      ...

      please help,
      tia,
      Dave

        • 1. Re: CMP Update problem
          Dave Newbie

          In addition, you can find my ejb-jar.xml settings.

          What I don't get is the fact that when JBoss tries to remove the language from the article, it looksup all articles with that language attached to it (this is what i can read from the server logs). If you want to, I can always send you the server logs by mail (as the attach file mechanism doesn't work on the forum).

          /// EJB-JAR.XML ////////////////////////////////////////
          ...


          Models an article
          <ejb-name>ArticleEJB</ejb-name>

          <local-home>com.presscollection.ejb.entity.LocalArticleHome</local-home>
          com.presscollection.ejb.entity.LocalArticle
          <ejb-class>com.presscollection.ejb.entity.ArticleBean</ejb-class>

          <persistence-type>Container</persistence-type>
          <prim-key-class>java.lang.Integer</prim-key-class>
          False
          <cmp-version>2.x</cmp-version>
          <abstract-schema-name>Article</abstract-schema-name>

          <cmp-field><field-name>id</field-name></cmp-field>
          <cmp-field><field-name>title</field-name></cmp-field>
          <cmp-field><field-name>subject</field-name></cmp-field>
          <cmp-field><field-name>freetext</field-name></cmp-field>
          <cmp-field><field-name>header</field-name></cmp-field>
          <cmp-field><field-name>body</field-name></cmp-field>
          <cmp-field><field-name>caption</field-name></cmp-field>

          <primkey-field>id</primkey-field>


          findAll
          <query-method>
          <method-name>findAll</method-name>
          <method-params/>
          </query-method>
          <ejb-ql/>



          ...


          Models a language
          <ejb-name>LanguageEJB</ejb-name>

          <local-home>com.presscollection.ejb.entity.LocalLanguageHome</local-home>
          com.presscollection.ejb.entity.LocalLanguage
          <ejb-class>com.presscollection.ejb.entity.LanguageBean</ejb-class>

          <persistence-type>Container</persistence-type>
          <prim-key-class>java.lang.Integer</prim-key-class>
          False
          <cmp-version>2.x</cmp-version>
          <abstract-schema-name>Language</abstract-schema-name>

          <cmp-field><field-name>id</field-name></cmp-field>
          <cmp-field><field-name>code</field-name></cmp-field>
          <cmp-field><field-name>name</field-name></cmp-field>

          <primkey-field>id</primkey-field>


          findAll
          <query-method>
          <method-name>findAll</method-name>
          <method-params/>
          </query-method>
          <ejb-ql/>



          ...
          <ejb-relation>
          <ejb-relation-name>Article-Language</ejb-relation-name>

          <ejb-relationship-role>
          <ejb-relationship-role-name>article-has-language</ejb-relationship-role-name>

          One

          <relationship-role-source>
          <ejb-name>ArticleEJB</ejb-name>
          </relationship-role-source>

          <cmr-field>
          <cmr-field-name>language</cmr-field-name>
          </cmr-field>
          </ejb-relationship-role>

          <ejb-relationship-role>
          <ejb-relationship-role-name>language-of-article</ejb-relationship-role-name>

          One

          <relationship-role-source>
          <ejb-name>LanguageEJB</ejb-name>
          </relationship-role-source>
          </ejb-relationship-role>
          </ejb-relation>
          ...
          ////////////////////////////////////////////////////////

          The code I execute
          /// CODE ///////////////////////////////////////////////

          LocalLanguage language;
          LocalLanguageHome languageHome =
          ( LocalLanguageHome ) EJBResourceFactory.getFactory().lookUpLocalHome( LocalLanguageHome.class );
          LocalArticle article;
          LocalArticleHome articleHome =
          ( LocalArticleHome ) EJBResourceFactory.getFactory().lookUpLocalHome( LocalArticleHome.class );

          article = articleHome.findByPrimaryKey( new Integer( articleId ) );

          if ( article != null )
          {
          System.out.println( "UPDATING LANGUAGE [" + languageId + "]" );

          // update language
          language = languageHome.findByPrimaryKey( new Integer( languageId ) );
          System.out.println( "LANG = [" + language + "]" );
          article.setLanguage( language );
          System.out.println( "LANG SET TO NEW LANG" );
          }

          ////////////////////////////////////////////////////////



          I'm completely stuck with this one, so a little bit of help is more than welcome.

          Thanks in advance,
          Dave

          • 2. Re: CMP Update problem
            Dain Sundstrom Master

            I don't see any problems with the posted code. Have you tried removing the findAll query declarations or the correct ejb-ql for findAll in the ejb-ql element (SELECT OBJEC(a) FROM Article a).

            • 3. Re: CMP Update problem
              Dave Newbie

              Unfortunally, that didn't do the trick :(

              I tried to remove both the findAll queries for Article and language. But I'm not using these finder methods.

              I start from my test client, from which I call my remote ArticleFacade session bean. This bean then calls the findByPrimaryKey for the article as well as the language.

              I've attached my jboss.xml, ejb-jar.xml, jbosscmp-jdbc.xml and my server logs.
              I find it very odd that when it tries to do the remove relation method, it looks up all articles with the language that I try to remove. You can see this behaviour in my server logs. I don't know if this is causing the troubles?

              I really appreciate any help,
              Dave

              • 4. Re: CMP Update problem
                Dave Newbie

                small correction :
                it doesn't lookup all articles with the language that it tries to remove, but all articles with the language that I'm trying to set to the given article.

                f.e.
                - article (ID=1) has languageID 1
                - when I try to set language with ID 4 to my article, it looks up all articles with languageID 4
                I have no clue why ...

                • 5. Re: CMP Update problem
                  Dave Newbie

                  I figured out that when I try to set a language that is not yet assigned to another article, my update works just fine.

                  From the moment that the language is already assigned to another article, I get the error ...

                  I hope this can assist in finding the problem ...

                  • 6. Re: CMP Update problem
                    Dave Newbie

                    Problem fixed ...
                    nevermind ...

                    • 7. Re: CMP Update problem
                      prabhakar Newbie

                      i am getting the same exception when trying to create a patient bean and then update a cmr field(location) in the ejbpostcreate method of patient bean(shown in the example below)

                      location---------> patient
                      1 many (unidirectional)
                      i am having only local,localHome interfaces for both the beans and location is represented only as cmr field in the patient bean

                      request to help on how to solve this problem