8 Replies Latest reply on Jul 23, 2004 2:16 AM by Alexey Loubyansky

    CMR and compound primary keys

    David Green Newbie

      Is CMR supported with compound primary keys? I've had troubles getting this to work. The error that I get is as follows:

      org.jboss.deployment.DeploymentException: Atleast one role of a
      foreign-key mapped relationship must have key fields (or <primkey-field>
      is missing from ejb-jar.xml)

        • 1. Re: CMR and compound primary keys
          Alexey Loubyansky Master

          Supported. If you declare relationships in jbosscmp-jdbc.xml you should map the key fields (primary to foreign key mapping).

          • 2. Re: CMR and compound primary keys
            Somporn Jomnsauan Newbie

            Alexey Loubyansky
            CMP Lead Developer
            JBoss, Inc
            I think you Expert ofr JBoss
            I have Some Problem
            to ask you
            JBoss Support Multi Compond Primary Key Or Multi Composite Primary Keys in such sutiation as I have
            2 Entity bean and How Specifice in XDoclet tag
            SALEOrderBean have 2 Primary keys wich map
            SO_HEADER Table ==>(BOOK_CD(PK),DOCNO(PK), DOCDT,....., ect);
            SO_ITEM Table==>(BOOK_CD(PK) wtih foreign key from SO_HEADER,DOCNO(PK) wtih foreign key from SO_HEADER, LINE_ITEM(PK), ......, ect);

            does JBoss support this case ?
            Thank you very much for Any boy for answer this Problem
            Please Post some code for clear
            Thank

            • 3. Re: CMR and compound primary keys
              David Green Newbie

              Fantastic! That's good news. After reading the JBossCMP.pdf, I've still got problems. Perhaps you could tell me what I'm doing wrong. Here are my deployment descriptors.

              my ejb-jar.xml:

              <ejb-jar>
               <display-name>FooBar</display-name>
               <enterprise-beans>
               <entity>
               <display-name>Customer</display-name>
               <ejb-name>Customer</ejb-name>
               <local-home>com.acme.foobar.objectmodel.CustomerLocalHome</local-home>
               <local>com.acme.foobar.objectmodel.CustomerLocal</local>
               <ejb-class>com.acme.foobar.objectmodel.imp.CustomerBean</ejb-class>
               <persistence-type>Container</persistence-type>
               <prim-key-class>com.acme.foobar.objectmodel.CustomerPrimaryKey</prim-key-class>
               <!--reentrancy is discouraged by the spec. See section 10.5.11-->
               <reentrant>False</reentrant>
               <cmp-version>2.x</cmp-version>
               <abstract-schema-name>Customer</abstract-schema-name>
               <cmp-field>
               <field-name>customerId</field-name>
               </cmp-field>
               <cmp-field>
               <field-name>customerSIN</field-name>
               </cmp-field>
               <ejb-local-ref>
               <ejb-ref-name>ejb/CustomerAddress</ejb-ref-name>
               <ejb-ref-type>Entity</ejb-ref-type>
               <local-home>com.acme.foobar.objectmodel.CustomerAddressLocalHome</local-home>
               <local>com.acme.foobar.objectmodel.CustomerAddressLocal</local>
               <ejb-link>CustomerAddress</ejb-link>
               </ejb-local-ref>
               </entity>
               <entity>
               <display-name>CustomerAddress</display-name>
               <ejb-name>CustomerAddress</ejb-name>
               <local-home>com.acme.foobar.objectmodel.CustomerAddressLocalHome</local-home>
               <local>com.acme.foobar.objectmodel.CustomerAddressLocal</local>
               <ejb-class>com.acme.foobar.objectmodel.imp.CustomerAddressBean</ejb-class>
               <persistence-type>Container</persistence-type>
               <prim-key-class>java.lang.Long</prim-key-class>
               <!--reentrancy is discouraged by the spec. See section 10.5.11-->
               <reentrant>False</reentrant>
               <cmp-version>2.x</cmp-version>
               <abstract-schema-name>CustomerAddress</abstract-schema-name>
               <cmp-field>
               <field-name>customerAddressId</field-name>
               </cmp-field>
               <primkey-field>customerAddressId</primkey-field>
               <ejb-local-ref>
               <ejb-ref-name>ejb/Customer</ejb-ref-name>
               <ejb-ref-type>Entity</ejb-ref-type>
               <local-home>com.acme.foobar.objectmodel.CustomerLocalHome</local-home>
               <local>com.acme.foobar.objectmodel.CustomerLocal</local>
               <ejb-link>Customer</ejb-link>
               </ejb-local-ref>
               </entity>
               </enterprise-beans>
               <relationships>
               <ejb-relation>
               <description><![CDATA[Customer has CustomerAddress
               (CustomerAddress refers to Customer)
               min occurs:
               max occurs:
               constraint: ]]></description>
               <ejb-relation-name>CustomerAddress-CustomerPKeyKeyref</ejb-relation-name>
               <ejb-relationship-role>
               <ejb-relationship-role-name>CustomerAddress-CustomerPKeyKeyref-master</ejb-relationship-role-name>
               <multiplicity>One</multiplicity>
               <relationship-role-source>
               <ejb-name>Customer</ejb-name>
               </relationship-role-source>
               <cmr-field>
               <cmr-field-name>customerAddresss</cmr-field-name>
               <cmr-field-type>java.util.Collection</cmr-field-type>
               </cmr-field>
               </ejb-relationship-role>
               <ejb-relationship-role>
               <ejb-relationship-role-name>CustomerAddress-CustomerPKeyKeyref-detail</ejb-relationship-role-name>
               <multiplicity>Many</multiplicity>
               <relationship-role-source>
               <ejb-name>CustomerAddress</ejb-name>
               </relationship-role-source>
               <cmr-field>
               <cmr-field-name>customer</cmr-field-name>
               </cmr-field>
               </ejb-relationship-role>
               </ejb-relation>
               </relationships>
               <assembly-descriptor>
               <method-permission>
               <description><![CDATA[
               Permissions for the Customer entity bean.
               ]]></description>
               <!--Everyone may have access to this item-->
               <unchecked/>
               <method>
               <ejb-name>Customer</ejb-name>
               <method-name>*</method-name>
               </method>
               </method-permission>
               <method-permission>
               <description><![CDATA[
               Permissions for the CustomerAddress entity bean.
               ]]></description>
               <!--Everyone may have access to this item-->
               <unchecked/>
               <method>
               <ejb-name>CustomerAddress</ejb-name>
               <method-name>*</method-name>
               </method>
               </method-permission>
               <container-transaction>
               <method>
               <ejb-name>Customer</ejb-name>
               <method-name>*</method-name>
               </method>
               <method>
               <ejb-name>CustomerAddress</ejb-name>
               <method-name>*</method-name>
               </method>
               <trans-attribute>Mandatory</trans-attribute>
               </container-transaction>
               </assembly-descriptor>
              </ejb-jar>
              


              my jbosscmp-jdbc.xml:

              <jbosscmp-jdbc>
               <defaults>
               <datasource>java:/DefaultDataSource</datasource>
               <datasource-mapping>DefaultDataSourceMapping</datasource-mapping>
               <!--get-generated-keys-DefaultDataSource must be defined in the commands section of the data source mapping-->
               <entity-command name="get-generated-keys-DefaultDataSource"/>
               </defaults>
               <enterprise-beans>
               <entity>
               <ejb-name>Customer</ejb-name>
               <create-table>false</create-table>
               <remove-table>false</remove-table>
               <table-name>Customer</table-name>
               <cmp-field>
               <field-name>customerId</field-name>
               <column-name>CustomerId</column-name>
               <not-null/>
               </cmp-field>
               <cmp-field>
               <field-name>customerSIN</field-name>
               <column-name>CustomerSIN</column-name>
               <not-null/>
               </cmp-field>
               <audit/>
               </entity>
               <entity>
               <ejb-name>CustomerAddress</ejb-name>
               <create-table>false</create-table>
               <remove-table>false</remove-table>
               <table-name>CustomerAddress</table-name>
               <cmp-field>
               <field-name>customerAddressId</field-name>
               <column-name>CustomerAddressId</column-name>
               <not-null/>
               </cmp-field>
               <audit/>
               </entity>
               </enterprise-beans>
               <relationships>
               <ejb-relation>
               <ejb-relation-name>CustomerAddress-CustomerPKeyKeyref</ejb-relation-name>
               <foreign-key-mapping/>
               <ejb-relationship-role>
               <ejb-relationship-role-name>CustomerAddress-CustomerPKeyKeyref-master</ejb-relationship-role-name>
               <key-fields>
               <key-field>
               <field-name>customerId</field-name>
               <column-name>CustomerId</column-name>
               </key-field>
               <key-field>
               <field-name>customerSIN</field-name>
               <column-name>CustomerSIN</column-name>
               </key-field>
               </key-fields>
               </ejb-relationship-role>
               <ejb-relationship-role>
               <ejb-relationship-role-name>CustomerAddress-CustomerPKeyKeyref-detail</ejb-relationship-role-name>
               <key-fields/>
               </ejb-relationship-role>
               </ejb-relation>
               </relationships>
              </jbosscmp-jdbc>
              


              Your help is greatly appreciated.

              • 4. Re: CMR and compound primary keys
                Alexey Loubyansky Master

                What is the problem now?

                • 5. Re: CMR and compound primary keys
                  David Green Newbie

                  The problem is the same as the described in the first posting of this thread. here's the full stack trace:

                  
                  org.jboss.deployment.DeploymentException: Atleast one role of a foreign-key mapped relationship must have key fields (or <primkey-field> is missing from ejb-jar.xml): ejb-relation-name=CustomerAddress-CustomerPKeyKeyref
                   at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCRelationMetaData.<init>(JDBCRelationMetaData.java:347)
                   at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCApplicationMetaData.<init>(JDBCApplicationMetaData.java:413)
                   at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCXmlFileLoader.load(JDBCXmlFileLoader.java:67)
                   at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.loadJDBCEntityMetaData(JDBCStoreManager.java:706)
                   at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.initStoreManager(JDBCStoreManager.java:409)
                   at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.start(JDBCStoreManager.java:357)
                   at org.jboss.ejb.plugins.CMPPersistenceManager.start(CMPPersistenceManager.java:152)
                   at org.jboss.ejb.EntityContainer.startService(EntityContainer.java:342)
                   at org.jboss.system.ServiceMBeanSupport.start(ServiceMBeanSupport.java:192)
                   at sun.reflect.GeneratedMethodAccessor46.invoke(Unknown Source)
                   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                   at java.lang.reflect.Method.invoke(Method.java:324)
                   at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
                   at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:546)
                   at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:976)
                   at $Proxy14.start(Unknown Source)
                   at org.jboss.system.ServiceController.start(ServiceController.java:394)
                   at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
                   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                   at java.lang.reflect.Method.invoke(Method.java:324)
                   at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
                   at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:546)
                   at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:177)
                   at $Proxy30.start(Unknown Source)
                   at org.jboss.ejb.EjbModule.startService(EjbModule.java:331)
                   at org.jboss.system.ServiceMBeanSupport.start(ServiceMBeanSupport.java:192)
                   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                   at java.lang.reflect.Method.invoke(Method.java:324)
                   at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
                   at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:546)
                   at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:976)
                   at $Proxy14.start(Unknown Source)
                   at org.jboss.system.ServiceController.start(ServiceController.java:394)
                   at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
                   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                   at java.lang.reflect.Method.invoke(Method.java:324)
                   at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
                   at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:546)
                   at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:177)
                   at $Proxy12.start(Unknown Source)
                   at org.jboss.ejb.EJBDeployer.start(EJBDeployer.java:544)
                   at org.jboss.deployment.MainDeployer.start(MainDeployer.java:832)
                   at org.jboss.deployment.MainDeployer.start(MainDeployer.java:824)
                   at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:642)
                   at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:605)
                   at sun.reflect.GeneratedMethodAccessor19.invoke(Unknown Source)
                   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                   at java.lang.reflect.Method.invoke(Method.java:324)
                   at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
                   at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:546)
                   at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:177)
                   at $Proxy6.deploy(Unknown Source)
                   at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:302)
                   at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:476)
                   at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:201)
                   at org.jboss.deployment.scanner.AbstractDeploymentScanner.startService(AbstractDeploymentScanner.java:274)
                   at org.jboss.system.ServiceMBeanSupport.start(ServiceMBeanSupport.java:192)
                   at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
                   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                   at java.lang.reflect.Method.invoke(Method.java:324)
                   at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
                   at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:546)
                   at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:976)
                   at $Proxy0.start(Unknown Source)
                   at org.jboss.system.ServiceController.start(ServiceController.java:394)
                   at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
                   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                   at java.lang.reflect.Method.invoke(Method.java:324)
                   at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
                   at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:546)
                   at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:177)
                   at $Proxy4.start(Unknown Source)
                   at org.jboss.deployment.SARDeployer.start(SARDeployer.java:226)
                   at org.jboss.deployment.MainDeployer.start(MainDeployer.java:832)
                   at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:642)
                   at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:605)
                   at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:589)
                   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                   at java.lang.reflect.Method.invoke(Method.java:324)
                   at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
                   at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:546)
                   at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:177)
                   at $Proxy5.deploy(Unknown Source)
                   at org.jboss.system.server.ServerImpl.doStart(ServerImpl.java:384)
                   at org.jboss.system.server.ServerImpl.start(ServerImpl.java:291)
                   at org.jboss.Main.boot(Main.java:150)
                   at org.jboss.Main$1.run(Main.java:395)
                   at java.lang.Thread.run(Thread.java:534)
                  


                  • 6. Re: CMR and compound primary keys
                    Alexey Loubyansky Master

                    The deployment descriptors seem to be ok. But looks like the jbosscmp-jdbc.xml is not found or another version of it is used.

                    • 7. Re: CMR and compound primary keys
                      David Green Newbie

                      I have confirmed that there is no other jbosscmp-jdbc.xml, and I know that it's finding the given one since if I change the example code to use a non-composite primary key the whole thing works.

                      From the error message, it looks like JBoss is looking for a <primkey-field> in the ejb-jar.xml, but obviously there is none since it's a compound primary key.

                      Suggestions?

                      • 8. Re: CMR and compound primary keys
                        Alexey Loubyansky Master

                        CustomerAddress has prim-key-class java.lang.Long. That's why it expects the primkey-field.