0 Replies Latest reply on Sep 3, 2004 12:13 PM by Sathya Sekar

    Clarification required on 1-Many CMR

    Sathya Sekar Newbie

      Hi,

      Presenting the scenario. I have 2 DB tables - Customer and Address having a 1-Many relationship :

      Table : Customer
      CustID VARCHAR(10) PRIMARY-KEY
      CustName VARCHAR(50)
      
      Table : CustomerAddress
      CustID VARCHAR(10)
      AddressIndex INTEGER
      Address VARCHAR(1000)
      
      Sample Data :
      
      Customer :
      A1 Customer1
      
      CustomerAddress :
      A1 1 Somewhere in the world
      


      Now, I want to establish this in my EJB. I wrote the requisite relationship methods. My relationship node in the ejb-jar.xml is :

       <relationships >
       <ejb-relation >
       <ejb-relation-name>Customer-Addresses</ejb-relation-name>
      
       <ejb-relationship-role >
       <ejb-relationship-role-name>Customer-has-addresses</ejb-relationship-role-name>
       <multiplicity>One</multiplicity>
       <relationship-role-source >
       <ejb-name>Customer</ejb-name>
       </relationship-role-source>
       <cmr-field >
       <cmr-field-name>addresses</cmr-field-name>
       <cmr-field-type>java.util.Collection</cmr-field-type>
       </cmr-field>
       </ejb-relationship-role>
      
       <ejb-relationship-role >
       <ejb-relationship-role-name>Addresses-of-customer</ejb-relationship-role-name>
       <multiplicity>Many</multiplicity>
       <cascade-delete/>
       <relationship-role-source >
       <ejb-name>CustomerAddress</ejb-name>
       </relationship-role-source>
       </ejb-relationship-role>
      
       </ejb-relation>
       </relationships>
      


      and the one in my jbosscmp-jdbc.xml is :

       <relationships>
       <ejb-relation>
       <ejb-relation-name>Customer-Addresses</ejb-relation-name>
      
       <ejb-relationship-role>
       <ejb-relationship-role-name>Customer-has-addresses</ejb-relationship-role-name>
       <key-fields>
       <key-field>
       <field-name>customerID</field-name>
       <column-name>customerID</column-name>
       </key-field>
       </key-fields>
      
       </ejb-relationship-role>
       <ejb-relationship-role>
       <ejb-relationship-role-name>Addresses-of-customer</ejb-relationship-role-name>
       <key-fields>
       <key-field>
       <field-name>customerID</field-name>
       <column-name>customerID</column-name>
       </key-field>
       </key-fields>
      
       </ejb-relationship-role>
       </ejb-relation>
       </relationships>
      


      But when I deploy the XML, the below error is thrown :

      20:26:34,938 ERROR [EntityContainer] Starting failed jboss.j2ee:jndiName=ejb/CustomerAddressHome,service=EJB
      org.jboss.deployment.DeploymentException: Mappings were not provided for all fields: unmaped fields=[addressIndex] in role= Addresses-of-customer
       at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCRelationshipRoleMetaData.loadKeyFields(JDBCRelationshipRoleMetaData.java:453)
       at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCRelationshipRoleMetaData.init(JDBCRelationshipRoleMetaData.java:184)
       at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCRelationMetaData.<init>(JDBCRelationMetaData.java:351)
       at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCApplicationMetaData.<init>(JDBCApplicationMetaData.java:471)
       at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCXmlFileLoader.load(JDBCXmlFileLoader.java:75)
       at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.loadJDBCEntityMetaData(JDBCStoreManager.java:705)
      


      Now, addressIndex is also a primary key in the CustomerAddressBean but it has no part in the relationship !

      Any help please on this ? Should this addressIndex be a part of the relationship ?

      Thanks for any help