<ejb-jar xmlns="http://caucho.com/ns/resin">
  <enterprise-beans>
    <!--
       - Teacher CMP bean
      -->
    <entity>
      <ejb-name>ejbql_teacher</ejb-name>
      <local-home>example.cmp.ejbql.TeacherHome</local-home>
      <local>example.cmp.ejbql.Teacher</local>
      <ejb-class>example.cmp.ejbql.TeacherBean</ejb-class>

      <persistence-type>Container</persistence-type>
      <prim-key-class>String</prim-key-class>
      <reentrant>True</reentrant>
      <cmp-version>2.x</cmp-version>

      <abstract-schema-name>ejbql_teacher</abstract-schema-name>

      <cmp-field>
        <field-name>name</field-name>
      </cmp-field>

      <primkey-field>name</primkey-field>

      <query>
        <query-method>
          <method-name>findByStudent</method-name>
          <method-params>
            <method-param>java.lang.String</method-param>
          </method-params>
        </query-method>
        <ejb-ql>
          <![CDATA[SELECT course.teacher FROM ejbql_student student, IN(student.courseList) course WHERE student.name=?1]]>
        </ejb-ql>
      </query>
    </entity>

    <!--
       - Course CMP bean
      -->
    <entity>
      <ejb-name>ejbql_course</ejb-name>
      <local-home>example.cmp.ejbql.CourseHome</local-home>
      <local>example.cmp.ejbql.Course</local>
      <ejb-class>example.cmp.ejbql.CourseBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>String</prim-key-class>
      <reentrant>True</reentrant>

      <abstract-schema-name>ejbql_course</abstract-schema-name>

      <cmp-field>
        <field-name>name</field-name>
      </cmp-field>

      <primkey-field>name</primkey-field>

      <query>
        <query-method>
          <method-name>findByHouse</method-name>
          <method-params>
            <method-param>java.lang.String</method-param>
          </method-params>
        </query-method>
        <ejb-ql>
          <![CDATA[SELECT DISTINCT OBJECT(course) FROM ejbql_student student, IN(student.courseList) course WHERE student.house.name=?1]]>
        </ejb-ql>
      </query>

    </entity>

    <!--
       - Student CMP bean
      -->
    <entity>
      <ejb-name>ejbql_student</ejb-name>
      <local-home>example.cmp.ejbql.StudentHome</local-home>
      <local>example.cmp.ejbql.Student</local>
      <ejb-class>example.cmp.ejbql.StudentBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>String</prim-key-class>
      <reentrant>True</reentrant>
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>ejbql_student</abstract-schema-name>

      <cmp-field>
        <field-name>name</field-name>
      </cmp-field>
      <cmp-field>
        <field-name>gender</field-name>
      </cmp-field>
      <primkey-field>name</primkey-field>

       <query>
          <query-method>
            <method-name>findAll</method-name>
            <method-params/>
          </query-method>
          <ejb-ql>
            <![CDATA[SELECT o FROM ejbql_student o]]>
          </ejb-ql>
       </query>
    </entity>

    <!--
       - House CMP bean
      -->
    <entity>
      <ejb-name>ejbql_house</ejb-name>
      <local-home>example.cmp.ejbql.HouseHome</local-home>
      <local>example.cmp.ejbql.House</local>
      <ejb-class>example.cmp.ejbql.HouseBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>String</prim-key-class>
      <reentrant>True</reentrant>
      <abstract-schema-name>ejbql_house</abstract-schema-name>
    
      <cmp-field>
        <field-name>name</field-name>
      </cmp-field>

      <primkey-field>name</primkey-field>
    </entity>
  </enterprise-beans>

  <relationships>

    <!--
       - n-m relation between ejbql_student and ejbql_course
      -->
    <ejb-relation>
      <ejb-relation-name>ejbql_student_course_mapping</ejb-relation-name>
      <ejb-relationship-role>
        <multiplicity>Many</multiplicity>
        <relationship-role-source>
          <ejb-name>ejbql_student</ejb-name>
        </relationship-role-source>
        <cmr-field>
          <cmr-field-name>courseList</cmr-field-name>
          <cmr-field-type>java.util.Collection</cmr-field-type>
        </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
        <multiplicity>Many</multiplicity>
        <relationship-role-source>
          <ejb-name>ejbql_course</ejb-name>
        </relationship-role-source>
        <cmr-field>
          <cmr-field-name>studentList</cmr-field-name>
          <cmr-field-type>java.util.Collection</cmr-field-type>
        </cmr-field>
      </ejb-relationship-role>
    </ejb-relation>

    <!--
       - 1-1 relation between ejbql_teacher and ejbql_course
      -->
    <ejb-relation>
      <ejb-relationship-role>
        <multiplicity>One</multiplicity>
        <relationship-role-source>
           <ejb-name>ejbql_teacher</ejb-name>
        </relationship-role-source>
        <cmr-field>
          <cmr-field-name>course</cmr-field-name>
        </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
        <multiplicity>One</multiplicity>  
        <relationship-role-source>
          <ejb-name>ejbql_course</ejb-name>
        </relationship-role-source>
        <cmr-field>
          <cmr-field-name>teacher</cmr-field-name>
        </cmr-field>
      </ejb-relationship-role>
    </ejb-relation>

    <!--
       - 1-n relation between ejbql_house and ejbql_student
      -->
    <ejb-relation>
      <ejb-relationship-role>
        <multiplicity>One</multiplicity>
        <relationship-role-source>
          <ejb-name>ejbql_house</ejb-name>
        </relationship-role-source>
        <cmr-field>
          <cmr-field-name>studentList</cmr-field-name>
        </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
        <multiplicity>Many</multiplicity>
        <relationship-role-source>
          <ejb-name>ejbql_student</ejb-name>
        </relationship-role-source>
        <cmr-field>
          <cmr-field-name>house</cmr-field-name>
        </cmr-field>
      </ejb-relationship-role>
    </ejb-relation>

  </relationships>
</ejb-jar>