0 Replies Latest reply on May 4, 2004 10:23 AM by pkrishnaswami

    Not able to create Container-Managed Bean

    pkrishnaswami Newbie

      I am trying to run the example in enterprise techtips (dec2002). THis involves a simple personBean along with 2 other beans -phoneBean and AddressBean. All three are entity beans and there is container managed relationship between them. I initially did not change the ejb-jar.xml which came with the example. I had create to jbosscmp-jdbc.xml and the contents are as below:

      <jbosscmp-jdbc>


      java:/dec2002
      <datasource-mapping>Firebird</datasource-mapping>
      <create-table>true</create-table>
      <remove-table>true</remove-table>
      <!-- <read-only>false</read-only>-->
      <pk-constraint>true</pk-constraint>
      <relation-mapping-style>foreign-key</relation-mapping-style>

      <read-ahead>
      on-load
      <page-size>1000</page-size>
      <eager-load-group>*</eager-load-group>
      </read-ahead>
      <list-cache-max>1000</list-cache-max>




      <ejb-name>AddressBean</ejb-name>
      <table-name>ADDRESSBEAN</table-name>
      <cmp-field>
      <field-name>postalcode</field-name>
      <column-name>CODE</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>street2</field-name>
      <column-name>STREET2</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>street1</field-name>
      <column-name>STREET1</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>region</field-name>
      <column-name>REGION</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>city</field-name>
      <column-name>CITY</column-name>
      </cmp-field>
      <!-- <cmp-field>-->
      <!-- <field-name>id</field-name>-->
      <!-- <column-name>ID</column-name>-->
      <!-- </cmp-field>-->





      <ejb-name>PersonBean</ejb-name>
      <table-name>PERSONBEAN</table-name>
      <cmp-field>
      <field-name>birthdate</field-name>
      <column-name>BIRTHDATE</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>gender</field-name>
      <column-name>GENDER</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>lastname</field-name>
      <column-name>LASTNAME</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>middlename</field-name>
      <column-name>MIDDLENAME</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>firstname</field-name>
      <column-name>FIRSTNAME</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>id</field-name>
      <column-name>ID</column-name>
      </cmp-field>



      <ejb-name>PhoneBean</ejb-name>
      <table-name>PHONEBEAN</table-name>
      <cmp-field>
      <field-name>phonetype</field-name>
      <column-name>PHONETYPE</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>areacode</field-name>
      <column-name>AREACODE</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>number</field-name>
      <column-name>NUMBER</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>extension</field-name>
      <column-name>EXTENSION</column-name>
      </cmp-field>
      <!-- <cmp-field>-->
      <!-- <field-name>id</field-name>-->
      <!-- <column-name>ID</column-name>-->
      <!-- </cmp-field>-->









      <ejb-relation>
      <ejb-relation-name>Person-Phone</ejb-relation-name>
      <foreign-key-mapping />
      <read-only>false</read-only>
      <read-time-out>300</read-time-out>

      <ejb-relationship-role>
      <ejb-relationship-role-name>Person-has-phones</ejb-relationship-role-name>
      <!-- <fk-constraint>true</fk-constraint>-->
      <key-fields>
      <key-field>
      <field-name>id</field-name>
      <column-name>phones</column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>


      <ejb-relationship-role>
      <ejb-relationship-role-name>Phone-belongs-to-Person</ejb-relationship-role-name>
      <!-- <fk-constraint>true</fk-constraint>-->
      <key-fields/>
      </ejb-relationship-role>


      </ejb-relation>

      <ejb-relation>
      <ejb-relation-name>Person-WorkAddress</ejb-relation-name>
      <foreign-key-mapping />
      <read-only>false</read-only>
      <read-time-out>300</read-time-out>

      <ejb-relationship-role>
      <ejb-relationship-role-name>Person-has-workAddress</ejb-relationship-role-name>
      <!-- <fk-constraint>true</fk-constraint>-->
      <key-fields>
      <key-field>
      <field-name>id</field-name>
      <column-name>workAddress</column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>


      <ejb-relationship-role>
      <ejb-relationship-role-name>workAddress-belongs-to-Person</ejb-relationship-role-name>
      <!-- <fk-constraint>true</fk-constraint>-->
      <key-fields/>
      </ejb-relationship-role>


      </ejb-relation>

      <ejb-relation>
      <ejb-relation-name>Person-HomeAddress</ejb-relation-name>
      <foreign-key-mapping/>
      <read-only>false</read-only>
      <read-time-out>300</read-time-out>

      <ejb-relationship-role>
      <ejb-relationship-role-name>Person-has-homeAddress</ejb-relationship-role-name>
      <!-- <fk-constraint>true</fk-constraint>-->
      <key-fields>
      <key-field>
      <field-name>id</field-name>
      <column-name>homeAddress</column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>


      <ejb-relationship-role>
      <ejb-relationship-role-name>homeAddress-belongs-to-Person</ejb-relationship-role-name>
      <!-- <fk-constraint>true</fk-constraint>-->
      <key-fields/>
      </ejb-relationship-role>


      </ejb-relation>




      </jbosscmp-jdbc>


      When I run the example, the PersonBean is created fine but creating the AddressBean returns a null reference.

      I then modified the ejb-jar.xml so that both AddressBean and phoneBean has a primary key, modified the ejbs and jbosscmp-jdbc.xml accordingly. Now everything worked fine.

      The example did not require that either PhoneBean or AddressBean have a seperate column ID as its primary key.

      I have browsed the web and read that it is possible to create CMP beans without primary keys.

      Is my jbsscmp-jdbc.xml wrong? Can somebody help me out?