1 Reply Latest reply on Oct 8, 2004 12:06 AM by Ivanisevic Yiu

    problem on 1 to many relationship of CMP 1.1

    Ivanisevic Yiu Newbie

      I have two beans Student and Teacher
      assume that each student can only have one teacher
      and each teacher can have more than one student.

      but when I deploy my bean , jboos always give me the exception message
      ----
      Depends On Me: org.jboss.deployment.DeploymentException: Configuration found in
      jbosscmp-jdbc.xml for relation Student-Teacher but relation is not a jbosscmp-j
      dbc-managed relation in ejb-jar.xml
      ----

      so, what's the problem?
      below are my xml files.

      ----

      ejb-jar.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee" version="2.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
       <display-name xml:lang="en">HelloBean</display-name>
       <enterprise-beans>
       <entity>
       <ejb-name>Student</ejb-name>
       <home>school.StudentHome</home>
       <remote>school.Student</remote>
       <ejb-class>school.StudentBean</ejb-class>
       <persistence-type>Container</persistence-type>
       <prim-key-class>java.lang.String</prim-key-class>
       <reentrant>false</reentrant>
       <cmp-version>1.x</cmp-version>
       <cmp-field>
       <description xml:lang="en">no description</description>
       <field-name>id</field-name>
       </cmp-field>
       <cmp-field>
       <description xml:lang="en">no description</description>
       <field-name>name</field-name>
       </cmp-field>
       <cmp-field>
       <description xml:lang="en">no description</description>
       <field-name>teacherId</field-name>
       </cmp-field>
       <primkey-field>id</primkey-field>
       <security-identity>
       <use-caller-identity/>
       </security-identity>
       </entity>
      
       <entity>
       <ejb-name>Teacher</ejb-name>
       <home>school.TeacherHome</home>
       <remote>school.Teacher</remote>
       <ejb-class>school.TeacherBean</ejb-class>
       <persistence-type>Container</persistence-type>
       <prim-key-class>java.lang.String</prim-key-class>
       <reentrant>false</reentrant>
       <cmp-version>1.x</cmp-version>
       <cmp-field>
       <description xml:lang="en">no description</description>
       <field-name>id</field-name>
       </cmp-field>
       <cmp-field>
       <description xml:lang="en">no description</description>
       <field-name>name</field-name>
       </cmp-field>
       <primkey-field>id</primkey-field>
       <security-identity>
       <use-caller-identity/>
       </security-identity>
       <entity>
      
       <ejb-relation>
       <ejb-relation-name>Student-Teacher</ejb-relation-name>
       <ejb-relationship-role>
       <ejb-relationship-role-name>Student-Has-Teacher</ejb-relationship-role-name>
       Many
       <relationship-role-source>
       <ejb-name>Student</ejb-name>
       </relationship-role-source>
       <cmr-field>
       <cmr-field-name>teacherId</cmr-field-name>
       </cmr-field>
       </ejb-relationship-role>
       <ejb-relationship-role>
       <ejb-relationship-role-name>Teacher-Has-Student</ejb-relationship-role-name>
       One
       <relationship-role-source>
       <ejb-name>Teacher</ejb-name>
       </relationship-role-source>
       <cmr-field>
       <cmr-field-name>students</cmr-field-name>
       <cmr-field-type>java.util.Collection</cmr-field-type>
       </cmr-field>
       </ejb-relationship-role>
       </ejb-relation>
       </enterprise-beans>
      </ejb-jar>
      
      



      -----------------------------------------------
      and the jbosscpm-jdbc.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE jbosscmp-jdbc PUBLIC "-//JBoss//DTD JBOSSCMP-JDBC 3.2//EN" "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_4_0.dtd">
      
      <jbosscmp-jdbc>
      <defaults>
       <datasource>java:/MySqlDS</datasource>
       <datasource-mapping>mySQL</datasource-mapping>
      </defaults>
      
      <enterprise-beans>
       <entity>
       <ejb-name>Teacher</ejb-name>
       <create-table>false</create-table>
       <remove-table>false</remove-table>
       <table-name>teacher</table-name>
       <cmp-field>
       <field-name>id</field-name>
       <column-name>id</column-name>
       </cmp-field>
       <cmp-field>
       <field-name>name</field-name>
       <column-name>name</column-name>
       </cmp-field>
       </entity>
       <entity>
       <ejb-name>Student</ejb-name>
       <create-table>false</create-table>
       <remove-table>false</remove-table>
       <table-name>hello</table-name>
       <cmp-field>
       <field-name>id</field-name>
       <column-name>id</column-name>
       </cmp-field>
       <cmp-field>
       <field-name>name</field-name>
       <column-name>name</column-name>
       </cmp-field>
       <cmp-field>
       <field-name>teacherId</field-name>
       <column-name>teacherId</column-name>
       </cmp-field>
       </entity>
      </enterprise-beans>
      
      <relationships>
       <ejb-relation>
       <ejb-relation-name>Student-Teacher</ejb-relation-name>
       <foreign-key-mapping/>
       <ejb-relationship-role>
       <ejb-relationship-role-name>Teacher-Has-Student</ejb- relationship-role-name>
       <key-fields>
       <key-field>
       <field-name>id</field-name>
       <column-name>id</column-name>
       </key-field>
       </key-fields>
       </ejb-relationship-role>
       <ejb-relationship-role>
       <ejb-relationship-role-name>Student-Has-Teacher</ejb-relationship-role-name>
       <key-fields/>
       </ejb-relationship-role>
       </ejb-relation>
       </relationships>
      </jbosscmp-jdbc>