2 Replies Latest reply on Apr 16, 2004 6:08 AM by null null

    grrr: simple 1-1 relation - no foreign key column

    null null Newbie

      Hi everybody,

      M going mad with this: I made two simple Entity Beans (Customer & Address) to test relationships. Both are working and deploying fine. They can also be used by the remote client - everything ok. But on deployment JBoss does not create the foreign key column to manage the relationship. I cann create a local address bean for the customer, but the setAddress-Method has no effect ( that´s clear - there is no col to store the addresses primary key, haha! ). What am I doing wrong??

      The ejb-jar.xml:

      <?xml version="1.0" ?>
      <!DOCTYPE ejb-jar PUBLIC
      "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
      "http://java.sun.com/dtd/ejb-jar_2_0.dtd">

      <ejb-jar>


      Dieser Deployment-Deskriptor enthaelt Informationen
      ueber die Entity-Beans Customer und Address.


      <enterprise-beans>


      <ejb-name>Customer</ejb-name>
      ejb.customerOneToOne.CustomerHome
      ejb.customerOneToOne.Customer
      <local-home>ejb.customerOneToOne.CustomerLocalHome</local-home>
      ejb.customerOneToOne.CustomerLocal
      <ejb-class>ejb.customerOneToOne.CustomerBean</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>CustomerBeanAPS</abstract-schema-name>
      <cmp-field>
      Die Id des Kunden
      <field-name>id</field-name>
      </cmp-field>
      <cmp-field>
      Der Vorname des Kunden
      <field-name>foreName</field-name>
      </cmp-field>
      <cmp-field>
      Der Nachname des Kunden
      <field-name>sureName</field-name>
      </cmp-field>
      <primkey-field>id</primkey-field>
      <ejb-local-ref>
      <ejb-ref-name>ejb/address</ejb-ref-name>
      <ejb-ref-type>Entity</ejb-ref-type>
      <local-home>ejb.addressOneToOne.AddressLocalHome</local-home>
      ejb.addressOneToOne.AddressLocal
      <ejb-link>Address</ejb-link>
      </ejb-local-ref>

      <query-method>
      <method-name> ejbSelectAllCustomerIdsWithName </method-name>
      <method-params>
      <method-param>java.lang.String</method-param>
      </method-params>
      </query-method>
      <ejb-ql>
      SELECT DISTINCT customer.id FROM CustomerBeanAPS AS customer WHERE customer.sureName = ?1
      </ejb-ql>




      <ejb-name>Address</ejb-name>
      ejb.addressOneToOne.AddressHome
      ejb.addressOneToOne.Address
      <local-home>ejb.addressOneToOne.AddressLocalHome</local-home>
      ejb.addressOneToOne.AddressLocal
      <ejb-class>ejb.addressOneToOne.AddressBean</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>AddressBeanAPS</abstract-schema-name>
      <cmp-field>
      Die Id der Adresse
      <field-name>id</field-name>
      </cmp-field>
      <cmp-field>
      Die Strasse der Adresse
      <field-name>street</field-name>
      </cmp-field>
      <cmp-field>
      Der Postcode der Adresse
      <field-name>postcode</field-name>
      </cmp-field>
      <primkey-field>id</primkey-field>


      </enterprise-beans>


      <ejb-relation>
      <ejb-relation-name>Ein Kunde hat eine Adresse</ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Kunde-hat-Adresse</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>Customer</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>address</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>

      <ejb-relationship-role>
      <ejb-relationship-role-name>Adresse-hat-Kunde</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>Address</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>
      </ejb-relation>

      </ejb-jar>




      The jbosscmp-jdbc.xml

      <?xml version="1.0"?>
      <!DOCTYPE jbosscmp-jdbc PUBLIC
      "-//JBoss//DTD JBOSSCMP-JDBC 3.2//EN"
      "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_2.dtd">

      <jbosscmp-jdbc>

      java:/EjbDataSource
      <datasource-mapping>mySQL</datasource-mapping>
      <create-table>true</create-table>
      <remove-table>true</remove-table>
      <!-- Wichtig!!! -->
      <read-only>false</read-only>


      <enterprise-beans>


      <ejb-name>Customer</ejb-name>
      <table-name>Customers</table-name>
      <cmp-field>
      <field-name>id</field-name>
      <column-name>cid</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>foreName</field-name>
      <column-name>fName</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>sureName</field-name>
      <column-name>sName</column-name>
      </cmp-field>



      <ejb-name>Address</ejb-name>
      <table-name>Addresses</table-name>
      <cmp-field>
      <field-name>id</field-name>
      <column-name>aid</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>street</field-name>
      <column-name>street</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>postcode</field-name>
      <column-name>pcode</column-name>
      </cmp-field>


      </enterprise-beans>



      <ejb-relation>
      <ejb-relation-name>Ein Kunde hat eine Adresse </ejb-relation-name>
      <foreign-key-mapping/>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Kunde-hat-Adresse</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>id</field-name>
      <column-name>aid</column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>

      <ejb-relationship-role>
      <ejb-relationship-role-name>Adresse-hat-Kunde</ejb-relationship-role-name>
      <key-fields/>
      </ejb-relationship-role>
      </ejb-relation>


      </jbosscmp-jdbc>



      Thank you!