0 Replies Latest reply on Mar 4, 2003 9:18 AM by m_korotkov

    to jboss developers: 1-1 CMR requires FKeys in both directio

    m_korotkov

      Hi!
      I am using JBoss 3.0.4 and found one interesting thing.
      I have 2 beans: EmployeeBean and UserBean. There is a 1-to-1 UNIDIRECTIONAL relationship between them - there is CMR field (UserLocal user) in EmployeeBean.
      So, ejb-jar looks like:

      <ejb-relation>

      <ejb-relation-name>Employee-User</ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Employee-May-Have-User</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>EmployeeBean</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>user</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>User-Belongs-To-Employee</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>UserBean</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>
      </ejb-relation>


      Then, jbosscmp-jdbc.xml looks like:

      <ejb-relation>
      <ejb-relation-name>Employee-User</ejb-relation-name>
      <foreign-key-mapping/>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Employee-May-Have-User</ejb-relationship-role-name>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>User-Belongs-To-Employee</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>id</field-name>
      <column-name>A14_id</column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>
      </ejb-relation>


      And SQL for Postgresql is:

      create table A00_Employees (
      A00_id SERIAL not null,
      A01_id INT4 not null,
      A07_id INT4 not null,
      A14_id INT4 null,A15_id INT4 not null,
      A00_forename VARCHAR(80) null,
      A00_surname VARCHAR(80) null,
      A00_patronymicName VARCHAR(80) null,
      A00_birthDate DATE null,
      A00_isDefault BOOLEAN not null,
      constraint PK_A00_EMPLOYEES primary key (A00_id),
      constraint FK_R00_EMPLOYER foreign key (A01_id)
      references A01_Companies (A01_id),
      constraint FK_R01_ADDRESS_BOOK_ENTRY foreign key (A07_id)
      references A07_AddressBookEntries (A07_id),
      constraint FK_R02_USER foreign key (A14_id)
      references A14_Users (A14_id),

      constraint FK_R03_EMPLOYEE_POSITION foreign key (A15_id)
      references A15_EmployeePositions (A15_id)
      );

      create table A14_Users (
      A14_id SERIAL not null,
      A14_username VARCHAR(25) not null,
      A14_password VARCHAR(25) not null,
      constraint PK_A14_USERS primary key (A14_id),
      constraint AK_USERNAME_A14_USER unique (A14_username)
      );


      So, there is no FK in A14_Users on the table A00_Employees. And If I used BMP instead of CMP, I could easily locate EmployeeBean by user id and UserBean by employee id.
      But JBoss throws SQL exception on attempt to load instance of UserBean:

      ERROR: Attribute "employeebean_user" not found.

      So, seems like JBoss can not handle such a kind of CMR, when there is only one FK in 2 tables that are used by 2 CMR beans.

      THank you for your help!