3 Replies Latest reply on Aug 16, 2004 11:32 AM by Stjepan Brbot

    Creating deployment descriptors for relationships

    Jerrold Eads Newbie

      I have two tables in my database, users and usercontact. Users primary key is userId, UserContact primary key and foreign key use the userId from the Users table. My deployment descriptor describing this relationship is below. When I try to remove a user from the database I get the error reported below. How do I describe the relationship so the container knows to remove the UserContact row prior to the Users row?

      ejbjar.xml:
      < !-- this is a One to One relationship -->
      < ejb-relation>
      < ejb-relation-name>UserContact_userId< /ejb-relation-name>
      < ejb-relationship-role>
      < description>UserContact has one Users< /description>
      < ejb-relationship-role-name>UserContact_has_Users< /ejb-relationship-role-name>
      < multiplicity>One< /multiplicity>
      < relationship-role-source>
      < ejb-name>MSSQLServer2000MetaData_UserContact< /ejb-name>
      < /relationship-role-source>
      < cmr-field>
      < cmr-field-name>userId< /cmr-field-name>
      < /cmr-field>
      < /ejb-relationship-role>
      < ejb-relationship-role>
      < description>one Users exists for UserContact< /description>
      < ejb-relationship-role-name>UsersRole< /ejb-relationship-role-name>
      < multiplicity>One< /multiplicity>
      < cascade-delete/>
      < relationship-role-source>
      < description>Users< /description>
      < ejb-name>MSSQLServer2000MetaData_Users< /ejb-name>
      < /relationship-role-source>
      < /ejb-relationship-role>
      < /ejb-relation>

      error:
      2004-07-22 13:09:37,812 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCRemoveEntityCommand.MSSQLServer2000MetaData_Users] Executing SQL: DELETE FROM Users WHERE UserID=?
      2004-07-22 13:09:37,828 ERROR [org.jboss.ejb.plugins.cmp.jdbc.JDBCRemoveEntityCommand.MSSQLServer2000MetaData_Users] Could not remove Primary key: Raghu
      java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]DELETE statement conflicted with COLUMN REFERENCE constraint 'FK__UserConta__UserI__7C8480AE'. The conflict occurred in database 'MetaData', table 'UserContact', column 'UserID'.