6 Replies Latest reply on Sep 18, 2005 7:27 AM by Tarek Kassem

    CMR with foreign key as part of primary key : OK with 3.2.1,

    Nicolas Regez Newbie

      Hello all

      We are currently developping an EJB/Web-App which uses CMP 2.0 and IBM DB2. We have been trying to upgrade from JBoss 3.2.1 to 3.2.3 and hereby experienced the following problem:

      There is a unidirectional one-to-many CMR between Bean1 and Bean2. The foreign key in Bean2 (p_nr) is part of its compound primary key (p_nr,kat) and is of type VARCHAR(15) in the database, String as the member of the bean. The values of p_nr are usually shorter than 15 characters, consist of eg seven characters ("2222372" in the example). In JBoss 3.2.1, when I call the get-accessor getPNr() of Bean2, everything is fine. But when I deploy the same ear to JBoss 3.2.3, a call of the get-accessor getPNr() of exactly the same instance of Bean2 produces the attached Exception.

      Nowhere in our code do we append the white spaces.

      Any hint or help will be highly appreciated.

      Nicolas


      2004-02-25 10:26:40,904 ERROR [org.jboss.ejb.plugins.LogInterceptor] TransactionRolledbackLocalException in method: public abstract java.lang.String Bean1Local.getPNr(), causedBy:
      java.lang.IllegalStateException: New value [2222372 ] of a foreign key field pNr changed the value of a primary key field pNr[2222372]
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMP2xFieldBridge.setInstanceValue(JDBCCMP2xFieldBridge.java:195)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.setForeignKey(JDBCCMRFieldBridge.java:1299)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.load(JDBCCMRFieldBridge.java:1283)
      at org.jboss.ejb.plugins.cmp.jdbc.ReadAheadCache.load(ReadAheadCache.java:391)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadEntityCommand.execute(JDBCLoadEntityCommand.java:111)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadEntityCommand.execute(JDBCLoadEntityCommand.java:72)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.loadEntity(JDBCStoreManager.java:612)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.loadEntity(JDBCStoreManager.java:594)
      at org.jboss.ejb.plugins.CMPPersistenceManager.loadEntity(CMPPersistenceManager.java:381)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.loadEntity(CachedConnectionInterceptor.java:352)
      at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invoke(EntitySynchronizationInterceptor.java:239)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:185)
      at org.jboss.ejb.plugins.EntityReentranceInterceptor.invoke(EntityReentranceInterceptor.java:114)
      at org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke(EntityInstanceInterceptor.java:163)
      at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockInterceptor.java:89)
      at org.jboss.ejb.plugins.EntityCreationInterceptor.invoke(EntityCreationInterceptor.java:54)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:84)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:297)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:128)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:118)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
      at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
      at org.jboss.ejb.EntityContainer.internalInvoke(EntityContainer.java:489)
      at org.jboss.ejb.Container.invoke(Container.java:700)
      at org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invoke(BaseLocalProxyFactory.java:375)
      at org.jboss.ejb.plugins.local.EntityProxy.invoke(EntityProxy.java:38)
      at $Proxy78.getPNr(Unknown Source)

      [...]

        • 1. Re: CMR with foreign key as part of primary key : OK with 3.
          Alexey Loubyansky Master

          Could you try it with 3.2.4RC1? It might already be fixed.

          • 2. Re: CMR with foreign key as part of primary key : OK with 3.
            flashwindcn Newbie

            Can you post your jbosscmp-jdbc.xml and ejb-jar.xml?

            • 3. Re: CMR with foreign key as part of primary key : OK with 3.
              Nicolas Regez Newbie

              Hello

              Thank you for your quick answers. Where can I get 3.2.4RC1 from?

              Nicolas


              The important extracts of the two xml-files:

              ==============================================

              <ejb-jar>
              <enterprise-beans>

              <![CDATA[]]>
              <display-name>Bean1</display-name>
              <ejb-name>Bean1</ejb-name>
              <local-home>Bean1LocalHome</local-home>
              Bean1Local
              <ejb-class>Bean1</ejb-class>
              <persistence-type>Container</persistence-type>
              <prim-key-class>Bean1PK</prim-key-class>
              False
              <cmp-version>2.x</cmp-version>
              <abstract-schema-name>One</abstract-schema-name>
              <cmp-field >
              <![CDATA[]]>
              <field-name>pNr</field-name>
              </cmp-field>
              [...]
              <ejb-local-ref >
              <ejb-ref-name>ejblocal/Bean2</ejb-ref-name>
              <ejb-ref-type>Entity</ejb-ref-type>
              <local-home>Bean2LocalHome</local-home>
              Bean2Local
              <ejb-link>Bean2</ejb-link>
              </ejb-local-ref>
              [...]
              <resource-ref >
              <res-ref-name>jdbc/myDS</res-ref-name>
              <res-type>javax.sql.DataSource</res-type>
              <res-auth>Container</res-auth>
              </resource-ref>


              [...]




              <![CDATA[]]>
              <display-name>Bean2</display-name>
              <ejb-name>Bean2</ejb-name>
              <local-home>Bean2LocalHome</local-home>
              Bean2Local
              <ejb-class>Bean2</ejb-class>
              <persistence-type>Container</persistence-type>
              <prim-key-class>Bean2PK</prim-key-class>
              False
              <cmp-version>2.x</cmp-version>
              <abstract-schema-name>Bean2</abstract-schema-name>
              <cmp-field >
              <![CDATA[]]>
              <field-name>pNr</field-name>
              </cmp-field>
              <cmp-field >
              <![CDATA[]]>
              <field-name>kat</field-name>
              </cmp-field>
              [...]
              <resource-ref >
              <res-ref-name>jdbc/myDS</res-ref-name>
              <res-type>javax.sql.DataSource</res-type>
              <res-auth>Container</res-auth>
              </resource-ref>


              [...]
              </enterprise-beans>



              <ejb-relation>
              <ejb-relation-name>One_Two</ejb-relation-name>
              <ejb-relationship-role >
              <ejb-relationship-role-name>Bean1-has-Bean2</ejb-relationship-role-name>
              One
              <relationship-role-source >
              <ejb-name>Bean1</ejb-name>
              </relationship-role-source>
              <cmr-field >
              <cmr-field-name>bean2</cmr-field-name>
              <cmr-field-type>java.util.Collection</cmr-field-type>
              </cmr-field>
              </ejb-relationship-role>
              <ejb-relationship-role >
              <ejb-relationship-role-name>Bean2-belongs-to-Bean1</ejb-relationship-role-name>
              Many
              <relationship-role-source >
              <ejb-name>Bean2</ejb-name>
              </relationship-role-source>
              </ejb-relationship-role>
              </ejb-relation>

              [...]

              [...]
              </ejb-jar>





              ==============================================

              <jbosscmp-jdbc>
              <enterprise-beans>

              <ejb-name>Bean1</ejb-name>
              <create-table>false</create-table>
              <remove-table>false</remove-table>
              <table-name>Entity1</table-name>
              <cmp-field>
              <field-name>pNr</field-name>
              <column-name>p_nr</column-name>
              </cmp-field>
              [...]
              <load-groups>
              <load-group>

              <load-group-name>fields</load-group-name>
              [...]
              </load-group>
              </load-groups>
              <eager-load-group>fields</eager-load-group>


              [...]



              <ejb-name>Bean2</ejb-name>
              <create-table>false</create-table>
              <remove-table>false</remove-table>
              <table-name>Entity2</table-name>
              <cmp-field>
              <field-name>pNr</field-name>
              <column-name>p_nr</column-name>
              </cmp-field>
              <cmp-field>
              <field-name>kat</field-name>
              <column-name>kat</column-name>
              </cmp-field>
              [...]
              <load-groups>
              <load-group>

              <load-group-name>fields</load-group-name>
              [...]
              </load-group>
              </load-groups>
              <eager-load-group>fields</eager-load-group>


              [...]


              </enterprise-beans>


              <ejb-relation>
              <ejb-relation-name>One_Two</ejb-relation-name>
              <ejb-relationship-role>
              <ejb-relationship-role-name>Bean1-has-Bean2</ejb-relationship-role-name>
              <key-fields>
              <key-field>
              <field-name>pNr</field-name>
              <column-name>p_nr</column-name>
              </key-field>
              </key-fields>

              <read-ahead>
              on-find
              <page-size>10</page-size>
              <eager-load-group>fields</eager-load-group>
              </read-ahead>
              </ejb-relationship-role>
              <ejb-relationship-role>
              <ejb-relationship-role-name>Bean2-belongs-to-Bean1</ejb-relationship-role-name>
              <fk-constraint>true</fk-constraint>
              <key-fields/>
              </ejb-relationship-role>
              </ejb-relation>

              [...]


              </jbosscmp-jdbc>

              • 4. Re: CMR with foreign key as part of primary key : OK with 3.
                Alexey Loubyansky Master

                You will need to check it out from the CVS. Instructions can be found on sf.net/projects/jboss
                If can't do it, please, provide me with a testcase. Thanks.

                • 5. Re: CMR with foreign key as part of primary key : OK with 3.
                  Nicolas Regez Newbie

                  Hi Alex

                  I checked out 3.2.4RC1, built it and will deploy our application with it shortly. I will report asap whether the problem is fixed or not. OK?

                  Thanks again.

                  Nicolas

                  • 6. Re: CMR with foreign key as part of primary key : OK with 3.
                    Tarek Kassem Newbie

                    Hi Alex
                    I have the same problem. I am using jboss 3.2.5. when I call the accessor
                    getCharFieldType on the MessageTypeStaticFields local intefarce, i get the same exception as above post. Any clue

                    Below related portion of ejb-jar.xml

                    <entity>
                     <description>Entity Bean ( CMP )</description>
                     <display-name>MessageType</display-name>
                     <ejb-name>MessageType</ejb-name>
                     <local-home>ae.comtrust.sdes.dexh.hubmanager.config.MessageTypeLocalHome</local-home>
                     <local>ae.comtrust.sdes.dexh.hubmanager.config.MessageTypeLocal</local>
                     <ejb-class>ae.comtrust.sdes.dexh.hubmanager.config.MessageTypeBean</ejb-class>
                     <persistence-type>Container</persistence-type>
                     <prim-key-class>java.lang.Integer</prim-key-class>
                     <reentrant>False</reentrant>
                     <cmp-version>2.x</cmp-version>
                     <abstract-schema-name>MessageType</abstract-schema-name>
                     <cmp-field>
                     <field-name>strMessageName</field-name>
                     </cmp-field>
                     <cmp-field>
                     <field-name>strServiceName</field-name>
                     </cmp-field>
                     <cmp-field>
                     <field-name>numCustomerId</field-name>
                     </cmp-field>
                     <cmp-field>
                     <field-name>strSchemaLocation</field-name>
                     </cmp-field>
                     <cmp-field>
                     <field-name>strReplySchemaLoc</field-name>
                     </cmp-field>
                     <cmp-field>
                     <field-name>strStylesheetLocation</field-name>
                     </cmp-field>
                     <cmp-field>
                     <field-name>strConnectionAddress</field-name>
                     </cmp-field>
                     <cmp-field>
                     <field-name>numConnectionPort</field-name>
                     </cmp-field>
                     <cmp-field>
                     <field-name>numApplyCustomerRules</field-name>
                     </cmp-field>
                     <cmp-field>
                     <field-name>numMessageTypeID</field-name>
                     </cmp-field>
                     <cmp-field>
                     <field-name>numParentMessageID</field-name>
                     </cmp-field>
                     <cmp-field>
                     <field-name>numMessageClass</field-name>
                     </cmp-field>
                     <cmp-field>
                     <field-name>strReplyStylesheetLocation</field-name>
                     </cmp-field>
                     <primkey-field>numMessageTypeID</primkey-field>
                     <security-role-ref>
                     <role-name>sender-role</role-name>
                     <role-link>sender</role-link>
                     </security-role-ref>
                     <security-identity>
                     <use-caller-identity/>
                     </security-identity>
                     <query>
                     <query-method>
                     <method-name>findAll</method-name>
                     <method-params/>
                     </query-method>
                     <ejb-ql>select object(o) from MessageType o</ejb-ql>
                     </query>
                     <query>
                     <query-method>
                     <method-name>findByMessageKeys</method-name>
                     <method-params>
                     <method-param>java.lang.String</method-param>
                     <method-param>java.lang.String</method-param>
                     <method-param>java.lang.String</method-param>
                     </method-params>
                     </query-method>
                     <ejb-ql>select object(o) from MessageType o where o.strMessageName = ?1 AND o.strServiceName = ?2 AND o.numCustomerId = ?3</ejb-ql>
                     </query>
                     </entity>
                     <entity>
                     <description>Entity Bean ( CMP )</description>
                     <display-name>MessageStaticFields</display-name>
                     <ejb-name>MessageStaticFields</ejb-name>
                     <local-home>ae.comtrust.sdes.dexh.hubmanager.config.MessageStaticFieldsLocalHome</local-home>
                     <local>ae.comtrust.sdes.dexh.hubmanager.config.MessageStaticFieldsLocal</local>
                     <ejb-class>ae.comtrust.sdes.dexh.hubmanager.config.MessageStaticFieldsBean</ejb-class>
                     <persistence-type>Container</persistence-type>
                     <prim-key-class>ae.comtrust.sdes.dexh.hubmanager.config.MessageStaticFieldsPK</prim-key-class>
                     <reentrant>False</reentrant>
                     <cmp-version>2.x</cmp-version>
                     <abstract-schema-name>MessageStaticFields</abstract-schema-name>
                     <cmp-field>
                     <field-name>numMessageTypeId</field-name>
                     </cmp-field>
                     <cmp-field>
                     <field-name>strFieldName</field-name>
                     </cmp-field>
                     <cmp-field>
                     <field-name>strFieldValue</field-name>
                     </cmp-field>
                     <cmp-field>
                     <field-name>charFieldType</field-name>
                     </cmp-field>
                     <cmp-field>
                     <field-name>boolAppenToMsg</field-name>
                     </cmp-field>
                     <query>
                     <query-method>
                     <method-name>findAll</method-name>
                     <method-params/>
                     </query-method>
                     <ejb-ql>select object(o) from MessageStaticFields o</ejb-ql>
                     </query>
                     </entity>
                     <ejb-relation>
                     <ejb-relation-name>MessageType - MessageStaticFields</ejb-relation-name>
                     <ejb-relationship-role>
                     <ejb-relationship-role-name>Each message type has one or more static fields</ejb-relationship-role-name>
                     <multiplicity>One</multiplicity>
                     <relationship-role-source>
                     <ejb-name>MessageType</ejb-name>
                     </relationship-role-source>
                     <cmr-field>
                     <cmr-field-name>messageStaticFields</cmr-field-name>
                     <cmr-field-type>java.util.Collection</cmr-field-type>
                     </cmr-field>
                     </ejb-relationship-role>
                     <ejb-relationship-role>
                     <ejb-relationship-role-name>Each static field belongs to only one MessageType</ejb-relationship-role-name>
                     <multiplicity>Many</multiplicity>
                     <relationship-role-source>
                     <ejb-name>MessageStaticFields</ejb-name>
                     </relationship-role-source>
                     </ejb-relationship-role>
                     </ejb-relation>
                    


                    below is related portion of jbosscmp-jdbc.xml

                     <entity>
                     <ejb-name>MessageType</ejb-name>
                     <read-only>true</read-only>
                     <read-ahead>
                     <strategy>on-find</strategy>
                     <page-size>200</page-size>
                     <eager-load-group>*</eager-load-group>
                     </read-ahead>
                     <table-name>T_MESSAGE_TYPE</table-name>
                     <cmp-field>
                     <field-name>numMessageTypeID</field-name>
                     <column-name>NUM_MESSAGE_TYPE_ID</column-name>
                     </cmp-field>
                     <cmp-field>
                     <field-name>strMessageName</field-name>
                     <column-name>STR_MESSAGE_NAME</column-name>
                     </cmp-field>
                     <cmp-field>
                     <field-name>strServiceName</field-name>
                     <column-name>STR_SERVICE_NAME</column-name>
                     </cmp-field>
                     <cmp-field>
                     <field-name>numCustomerId</field-name>
                     <column-name>NUM_CUSTOMER_ID</column-name>
                     </cmp-field>
                     <cmp-field>
                     <field-name>strSchemaLocation</field-name>
                     <column-name>STR_SCHEMA_LOCATION</column-name>
                     </cmp-field>
                     <cmp-field>
                     <field-name>strReplySchemaLoc</field-name>
                     <column-name>STR_REPLY_SCHEMA_LOC</column-name>
                     </cmp-field>
                     <cmp-field>
                     <field-name>strStylesheetLocation</field-name>
                     <column-name>STR_STYLESHEET_LOCATION</column-name>
                     </cmp-field>
                     <cmp-field>
                     <field-name>strConnectionAddress</field-name>
                     <column-name>STR_CONNECTION_ADDRESS</column-name>
                     </cmp-field>
                     <cmp-field>
                     <field-name>numConnectionPort</field-name>
                     <column-name>NUM_CONNECTION_PORT</column-name>
                     </cmp-field>
                     <cmp-field>
                     <field-name>numApplyCustomerRules</field-name>
                     <column-name>BOOLEAN_APPLY_CUSTOMER_RULES</column-name>
                     </cmp-field>
                     <cmp-field>
                     <field-name>numParentMessageID</field-name>
                     <column-name>NUM_PARENT_MESSAGE_ID</column-name>
                     </cmp-field>
                     <cmp-field>
                     <field-name>numMessageClass</field-name>
                     <column-name>NUM_MESSAGE_TYPE</column-name>
                     </cmp-field>
                     <cmp-field>
                     <field-name>strReplyStylesheetLocation</field-name>
                     <column-name>STR_REPLY_STYLESHEET_LOCATION</column-name>
                     </cmp-field>
                     </entity>
                     <entity>
                     <ejb-name>MessageStaticFields</ejb-name>
                     <read-only>true</read-only>
                     <read-ahead>
                     <strategy>on-find</strategy>
                     <page-size>200</page-size>
                     <eager-load-group>*</eager-load-group>
                     </read-ahead>
                     <table-name>T_MESSAGE_STATIC_FIELDS</table-name>
                     <cmp-field>
                     <field-name>numMessageTypeId</field-name>
                     <column-name>NUM_MESSAGE_TYPE_ID</column-name>
                     </cmp-field>
                     <cmp-field>
                     <field-name>strFieldName</field-name>
                     <column-name>STR_FIELD_NAME</column-name>
                     </cmp-field>
                     <cmp-field>
                     <field-name>strFieldValue</field-name>
                     <column-name>STR_FIELD_VALUE</column-name>
                     </cmp-field>
                     <cmp-field>
                     <field-name>charFieldType</field-name>
                     <column-name>CHAR_FIELD_TYPE</column-name>
                     </cmp-field>
                     <cmp-field>
                     <field-name>boolAppenToMsg</field-name>
                     <column-name>BOOL_APPEND_TO_MSG</column-name>
                     </cmp-field>
                     </entity>
                     <ejb-relation>
                     <ejb-relation-name>MessageType - MessageStaticFields</ejb-relation-name>
                     <foreign-key-mapping/>
                     <ejb-relationship-role>
                     <ejb-relationship-role-name>Each message type has one or more static fields</ejb-relationship-role-name>
                     <key-fields>
                     <key-field>
                     <field-name>numMessageTypeID</field-name>
                     <column-name>NUM_MESSAGE_TYPE_ID</column-name>
                     </key-field>
                     </key-fields>
                     </ejb-relationship-role>
                     <ejb-relationship-role>
                     <ejb-relationship-role-name>Each static field belongs to only one MessageType</ejb-relationship-role-name>
                     <key-fields/>
                     </ejb-relationship-role>
                     </ejb-relation>
                    
                    
                    


                    below is the related portion in jboss.xml
                    <entity>
                     <ejb-name>MessageType</ejb-name>
                     <read-only>true</read-only>
                     <configuration-name>Read Only Standard CMP 2.x EntityBean</configuration-name>
                     </entity>
                     <entity>
                     <ejb-name>MessageStaticFields</ejb-name>
                     <read-only>true</read-only>
                     <configuration-name>Read Only Standard CMP 2.x EntityBean</configuration-name>
                     </entity>
                     <container-configuration extends="Standard CMP 2.x EntityBean">
                     <container-name>Read Only Standard CMP 2.x EntityBean</container-name>
                     <commit-option>D</commit-option>
                     <optiond-refresh-rate>1800</optiond-refresh-rate>
                     </container-configuration>
                    

                    the MessageType local interface
                    public interface MessageTypeLocal extends EJBLocalObject
                    {
                     String getStrMessageName();
                    
                     String getStrServiceName();
                    
                     String getNumCustomerId();
                    
                     String getStrSchemaLocation();
                    
                     void setStrSchemaLocation(String newStrSchemaLocation);
                    
                     String getStrReplySchemaLoc();
                    
                     void setStrReplySchemaLoc(String newStrReplySchemaLoc);
                    
                     String getStrStylesheetLocation();
                    
                     void setStrStylesheetLocation(String newStrStylesheetLocation);
                    
                    
                    
                     Long getNumConnectionPort();
                    
                     void setNumConnectionPort(Long newNumConnectionPort);
                    
                    
                    
                     int getNumApplyCustomerRules();
                    
                     void setNumApplyCustomerRules(int newNumApplyCustomerRules);
                    
                     Integer getNumMessageTypeID();
                    
                     String getStrConnectionAddress();
                    
                     void setStrConnectionAddress(String newStrConnectionAddress);
                    
                     Long getNumParentMessageID();
                    
                     void setNumParentMessageID(Long newNumParentMessageID);
                    
                     short getNumMessageClass();
                    
                     void setNumMessageClass(short newNumMessageClass);
                    
                     String getStrReplyStylesheetLocation();
                    
                     void setStrReplyStylesheetLocation(String newStrReplyStylesheetLocation);
                    
                     Collection getMessageStaticFields();
                    
                     void setMessageStaticFields(Collection newMessageStaticFields);
                    

                    The MessageStaticFields local interface
                    String getNumMessageTypeId();
                    
                     String getStrFieldName();
                    
                     String getStrFieldValue();
                    
                     void setStrFieldValue(String newStrFieldValue);
                    
                     String getCharFieldType();
                    
                     void setCharFieldType(String newCharFieldType);
                    
                     Boolean getBoolAppenToMsg();
                    
                     void setBoolAppenToMsg(Boolean newBoolAppenToMsg);