3 Replies Latest reply on Dec 11, 2002 4:21 AM by Sean Ryan

    Potential bug in JBoss 3.0 RC3-Tomcat - treating CMR fields

    Julio Newbie

      Hi all,

      Current configuration:
      * JBoss 3.0 RC3 - Tomcat 4.0.3 taken from SourceForge fiels page, NOT CVS
      * JDK 1.4
      * Windows NT environment

      When trying to create a User entity bean which contains a one-to-one relationship with a UserContact entity bean, I kept getting an SQL error stating that the 'contactInfo' column doesn't exist. However, I didn't configure 'contactInfo' as a CMP field, it was configured as a CMR field (can't attach, so pasting all code at bottom).

      I checked the code for the object responsible for generating the insert statements, and I found something curious. In the getInsertFields method in the org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand, the code goes as follows:

      ...
      private JDBCEntityBridge entity;
      ...

      private List getInsertFields() {
      List fields = entity.getFields();
      List insertFields = new ArrayList(fields.size());
      ...
      }

      The thing is, the JDBCEntityBridge.getFields method returns a list of ALL fields, both CMP and CMR. Shouldn't the JDBC command object call getCMPFields instead? When I made the changes, compiled it, and ran it on my system, the CMP engine generated the correct SQL statement to do the insert.

      Has anyone else noticed this? Is this a bug, or proper procedure and I'm just deploying incorrectly?

      ejb-jar.xml
      ========================================
      <ejb-jar>
      <enterprise-beans>

      <!-- ################################################################### -->
      <!-- Entity Bean: user.User -->
      <!-- ################################################################### -->

      Models a user of the site
      <ejb-name>user.User</ejb-name>
      com.alumis.user.ejb.cmp2.UserHome
      com.alumis.user.ejb.cmp2.User
      <local-home>com.alumis.user.ejb.cmp2.local.UserLocalHome</local-home>
      com.alumis.user.ejb.cmp2.local.UserLocal
      <ejb-class>com.alumis.user.ejb.cmp2.bean.UserBean</ejb-class>

      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Integer</prim-key-class>
      True

      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>User</abstract-schema-name>

      <cmp-field><field-name>customerId</field-name></cmp-field>
      <cmp-field><field-name>userName</field-name></cmp-field>
      <cmp-field><field-name>password</field-name></cmp-field>
      <cmp-field><field-name>email</field-name></cmp-field>
      <cmp-field><field-name>firstName</field-name></cmp-field>
      <cmp-field><field-name>lastName</field-name></cmp-field>
      <cmp-field><field-name>isBuyer</field-name></cmp-field>
      <cmp-field><field-name>isSeller</field-name></cmp-field>
      <cmp-field><field-name>dateJoined</field-name></cmp-field>
      <cmp-field><field-name>lastChanged</field-name></cmp-field>
      <cmp-field><field-name>isActive</field-name></cmp-field>

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





      <!-- ################################################################### -->
      <!-- Entity Bean: user.UserContact -->
      <!-- ################################################################### -->

      Models a user's contact information
      <ejb-name>user.UserContact</ejb-name>
      com.alumis.user.ejb.cmp2.UserContactHome
      com.alumis.user.ejb.cmp2.UserContact
      <local-home>com.alumis.user.ejb.cmp2.local.UserContactLocalHome</local-home>
      com.alumis.user.ejb.cmp2.local.UserContactLocal
      <ejb-class>com.alumis.user.ejb.cmp2.bean.UserContactBean</ejb-class>

      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Integer</prim-key-class>
      True

      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>UserContact</abstract-schema-name>

      <cmp-field>
      <field-name>userId</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>address</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>address2</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>city</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>state</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>zip</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>phone</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>fax</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>mobile</field-name>
      </cmp-field>


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


      </enterprise-beans>




      <ejb-relation>
      <ejb-relation-name>User-UserContact</ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>user-to-contact</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>user.User</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>contactInfo</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>

      <ejb-relationship-role>
      <ejb-relationship-role-name>contact-to-user</ejb-relationship-role-name>
      One
      <cascade-delete/>
      <relationship-role-source>
      <ejb-name>user.UserContact</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>
      </ejb-relation>




      jbosscmp-jdbc.xml
      ======================================
      <?xml version="1.0" encoding="ISO-8859-1"?>
      <jbosscmp-jdbc>
      <!-- ################################################################### -->
      <!-- Universal Options -->
      <!-- ################################################################### -->

      java:/mySQL.primaryDS
      <type-mapping>mySQL</type-mapping>
      <create-table>false</create-table>

      <enterprise-beans>
      <!-- ################################################################### -->
      <!-- Entity Bean: user.User -->
      <!-- ################################################################### -->

      <ejb-name>user.User</ejb-name>
      <table-name>USER_TABLE</table-name>
      <create-table>false</create-table>

      <cmp-field>
      <field-name>customerId</field-name>
      <column-name>CUSTOMER_ID</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>userName</field-name>
      <column-name>USERNAME</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>password</field-name>
      <column-name>PASSWORD</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>email</field-name>
      <column-name>EMAIL</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>firstName</field-name>
      <column-name>FIRST_NAME</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>lastName</field-name>
      <column-name>LAST_NAME</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>isBuyer</field-name>
      <column-name>IS_BUYER</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>isSeller</field-name>
      <column-name>IS_SELLER</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>dateJoined</field-name>
      <column-name>DATE_JOINED</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>lastChanged</field-name>
      <column-name>LAST_CHANGED</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>isActive</field-name>
      <column-name>ACTIVE</column-name>
      </cmp-field>

      <!-- PRIMARY FIELD MAPPING - CHANGE THE COLUMN NAME -->
      <cmp-field>
      <field-name>id</field-name>
      <column-name>USER_ID</column-name>
      </cmp-field>



      <!-- ################################################################### -->
      <!-- Entity Bean: user.UserContact -->
      <!-- ################################################################### -->

      <ejb-name>user.UserContact</ejb-name>
      <table-name>USER_CONTACT</table-name>
      <create-table>false</create-table>

      <cmp-field>
      <field-name>userId</field-name>
      <column-name>USER_ID</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>address</field-name>
      <column-name>ADDRESS</column-name>

      </cmp-field>
      <cmp-field>
      <field-name>address2</field-name>
      <column-name>ADDRESS2</column-name>

      </cmp-field>
      <cmp-field>
      <field-name>city</field-name>
      <column-name>CITY</column-name>

      </cmp-field>
      <cmp-field>
      <field-name>state</field-name>
      <column-name>STATE</column-name>

      </cmp-field>
      <cmp-field>
      <field-name>zip</field-name>
      <column-name>ZIP</column-name>

      </cmp-field>
      <cmp-field>
      <field-name>phone</field-name>
      <column-name>PHONE</column-name>

      </cmp-field>
      <cmp-field>
      <field-name>fax</field-name>
      <column-name>FAX</column-name>

      </cmp-field>
      <cmp-field>
      <field-name>mobile</field-name>
      <column-name>MOBILE</column-name>

      </cmp-field>

      <!-- PRIMARY FIELD MAPPING - CHANGE THE COLUMN NAME -->
      <cmp-field>
      <field-name>id</field-name>
      <column-name>USER_CONTACT_ID</column-name>
      </cmp-field>



      <!-- EJB Container Managed Relationship Declarations-->


      <ejb-relation>
      <ejb-relation-name>User-UserContact</ejb-relation-name>
      <foreign-key-mapping>
      <ejb-relationship-role>
      <ejb-relationship-role-name>user-to-contact</ejb-relationship-role-name>
      <foreign-key-fields/>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>contact-to-user</ejb-relationship-role-name>
      <foreign-key-fields>
      <foreign-key-field>
      <field-name>userId</field-name>
      <column-name>USER_ID</column-name>
      </foreign-key-field>
      </foreign-key-fields>
      </ejb-relationship-role>
      </foreign-key-mapping>
      </ejb-relation>



      </enterprise-beans>