1 Reply Latest reply on Feb 27, 2002 12:47 AM by Dain Sundstrom

    CMP2.0 Generating Bad SQL

    Jason Robertson Newbie

      I'm using code pulled from CVS on 02/20/02, and when attempting to load an entity it includes a relationship field in the SQL query:

      Executing SQL: SELECT name,description, orgTypeName, organizationType FROM role WHERE (name=?) OR (name=?) OR (name=?)

      The field organizationType is a cmr-field, so it doesn't exist in the database and this SQL statement throws an error.

      Here's my setup - anything wrong here?

      From ejb-xml.jar:



      <ejb-name>RoleEJB</ejb-name>
      com.acs.j2ee.framework.user.entity.RoleEntity
      <local-home>com.acs.j2ee.framework.user.entity.RoleEntityHome</local-home>
      <ejb-class>com.acs.j2ee.framework.user.entity.RoleEntityBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.String</prim-key-class>
      <primkey-field>name</primkey-field>
      false
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>RoleSchema</abstract-schema-name>

      <cmp-field>
      <field-name>name</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>description</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>orgTypeName</field-name>
      </cmp-field>





      <ejb-name>OrganizationTypeEJB</ejb-name>
      com.acs.j2ee.framework.user.entity.OrganizationTypeEntity
      <local-home>com.acs.j2ee.framework.user.entity.OrganizationTypeEntityHome</local-home>
      <ejb-class>com.acs.j2ee.framework.user.entity.OrganizationTypeEntityBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.String</prim-key-class>
      <primkey-field>name</primkey-field>
      false
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>OrganizationTypeSchema</abstract-schema-name>

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



      </enterprise-beans>


      <ejb-relation>
      <ejb-relation-name>Role-OrganizationType</ejb-relation-name>

      <ejb-relationship-role>
      <ejb-relationship-role-name>Role-Spawns-OrgType</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>RoleEJB</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>organizationType</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>

      <ejb-relationship-role>
      <ejb-relationship-role-name>OrgType-Fulfills-Role</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>OrganizationTypeEJB</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>

      </ejb-relation>


      From jbosscmp-jdbc.xml:

      <enterprise-beans>

      <ejb-name>OrganizationTypeEJB</ejb-name>
      <table-name>organizationtype</table-name>


      <ejb-name>RoleEJB</ejb-name>
      <table-name>role</table-name>

      </enterprise-beans>


      <ejb-relation>
      <ejb-relation-name>Role-OrganizationType</ejb-relation-name>
      <foreign-key-mapping>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Role-Spawns-OrgType</ejb-relationship-role-name>
      <foreign-key-fields>
      <foreign-key-field>
      <field-name>organizationType</field-name>
      <column-name>orgTypeName</column-name>
      </foreign-key-field>
      </foreign-key-fields>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>OrgType-Fulfills-Role</ejb-relationship-role-name>
      </ejb-relationship-role>
      </foreign-key-mapping>
      </ejb-relation>