0 Replies Latest reply on Sep 7, 2005 11:18 AM by rsuffling

    CMP 1:N Foreign Key Bug?

    rsuffling Newbie

      Has anyone come across this before? Is it a bug?
      JBoss is attempting to insert an invalid foreign key (FK) value. The FK value looks like something has overflowed:

      ¬í\0sr\0$org.jboss.invocation.MarshalledValueêÌàÑôJÐ \0\0xpz\0\0¢\0\0?¬í\0s}\0\0\0\0org.mycmp.auth.GroupLocalxr\0java.lang.reflect.Proxyá\'Ú ÌCË\0L\0ht\0%Ljava/lang/reflect/InvocationHandler;xpsr\0\'org.jboss.ejb.plugins.local.EntityProxyHm öE©\0Z\0removedL\0cacheKeyt\0Ljava/lang/Object;xr\0&org.jboss.ejb.plugins.local.LocalProxytgFß??qg\0L\0jndiNamet\0Ljava/lang/String;xpt\0local/GroupBean@14033637x\0sr\0java.lang.Integerâ ¤÷�?8\0I\0valuexr\0java.lang.Number?¬??à?\0\0xp\0\0\0®ñÐPx

      My envronment is:
      Windows XP
      JBoss AS 4.03RC2
      MySql 4.1.13

      The two entity ejbs/tables envolved in the 1:N relationship are Group and User, where a group can have many users and a user can belong to a group. The two entity beans have local interfaces and get called from a session bean (session facade pattern). The call (cut down version) made from the session bean is:

      public void addUser(String email, String password, String groupName, String firstName,
      String middleName, String lastName, String dept, String workPhone,
      String extension, String homePhone, boolean isEmployee) {
      try {
      GroupLocal group = groupHome.findByGroupName(groupName);
      UserLocal user = userHome.create(email, password, group);
      } catch (CreateException e) {
      throw new EJBException("Unable to create the local user " + email, e);
      }
      catch (FinderException e) {
      throw new EJBException("Group not Found. Unable to create the local user " + email, e);
      }

      }

      The resulting trace from the MySql log file is:
      Prepare [29] SELECT t0_group.ID FROM tbl_group t0_group WHERE (t0_group.NAME = ?)
      Execute [29] SELECT t0_group.ID FROM tbl_group t0_group WHERE (t0_group.NAME = 'engineering')
      Prepare [30] SELECT NAME, DESCRIPTION FROM tbl_group WHERE (ID=?)
      Execute [30] SELECT NAME, DESCRIPTION FROM tbl_group WHERE (ID=6)
      Prepare [31] SELECT COUNT(*) FROM tbl_user WHERE EMAIL=?
      Execute [31] SELECT COUNT(*) FROM tbl_user WHERE EMAIL='andy@rickhightower.com'
      Prepare [32] INSERT INTO tbl_user (EMAIL, PASSWORD, GROUP_ID) VALUES (?, ?, ?)
      Execute [32] INSERT INTO tbl_user (EMAIL, PASSWORD, GROUP_ID) VALUES ('andy@rickhightower.com', 'starwars', '¬í\0sr\0$org.jboss.invocation.MarshalledValueêÌàÑôJÐ \0\0xpz\0\0¢\0\0?¬í\0s}\0\0\0\0org.mycmp.auth.GroupLocalxr\0java.lang.reflect.Proxyá\'Ú ÌCË\0L\0ht\0%Ljava/lang/reflect/InvocationHandler;xpsr\0\'org.jboss.ejb.plugins.local.EntityProxyHm öE©\0Z\0removedL\0cacheKeyt\0Ljava/lang/Object;xr\0&org.jboss.ejb.plugins.local.LocalProxytgFß??qg\0L\0jndiNamet\0Ljava/lang/String;xpt\0local/GroupBean@14033637x\0sr\0java.lang.Integerâ ¤÷�?8\0I\0valuexr\0java.lang.Number?¬??à?\0\0xp\0\0\0®ñÐPx')
      Prepare [33] UPDATE tbl_user SET GROUP_ID=? WHERE EMAIL=?
      2 Execute [33] UPDATE tbl_user SET GROUP_ID='¬í\0sr\0$org.jboss.invocation.MarshalledValueêÌàÑôJÐ \0\0xpz\0\0¢\0\0?¬í\0s}\0\0\0\0org.mycmp.auth.GroupLocalxr\0java.lang.reflect.Proxyá\'Ú ÌCË\0L\0ht\0%Ljava/lang/reflect/InvocationHandler;xpsr\0\'org.jboss.ejb.plugins.local.EntityProxyHm öE©\0Z\0removedL\0cacheKeyt\0Ljava/lang/Object;xr\0&org.jboss.ejb.plugins.local.LocalProxytgFß??qg\0L\0jndiNamet\0Ljava/lang/String;xpt\0local/GroupBean@14033637x\0sr\0java.lang.Integerâ ¤÷�?8\0I\0valuexr\0java.lang.Number?¬??à?\0\0xp\0\0\0®ñÐPx' WHERE EMAIL='andy@rickhightower.com'
      Query commit


      The table structures are:

      CREATE TABLE TBL_GROUP
      ( id integer PRIMARY KEY AUTO_INCREMENT
      , name varchar (20) UNIQUE NOT NULL
      , description varchar (50)
      );

      CREATE TABLE TBL_USER
      ( email varchar (50) PRIMARY KEY
      , password varchar (50) NOT NULL
      , group_id integer
      );

      The problem seems to be when JBOSS process the call to
      UserLocal user = userHome.create(email, password, group);

      the UserBean code being called is as follows:

      public String ejbCreate(String email, String password, GroupLocal group) throws CreateException {
      setEmail(email);
      setPassword(password);
      setGroup(group);
      return null;
      }

      It's just the usual setter methods.

      The relationship in the ejb-jar.xml file is:

      <ejb-relation>
      <ejb-relation-name>GroupsHaveUsers</ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>GroupHasUsers</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>GroupBean</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>users</cmr-field-name>
      <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>UsersInGroup</ejb-relationship-role-name>
      Many
      <relationship-role-source>
      <ejb-name>UserBean</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>group</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>
      </ejb-relation>

      The jbosscmp-jdbc.xml file contains:

      <ejb-relation>
      <ejb-relation-name>GroupsHaveUsers</ejb-relation-name>
      <foreign-key-mapping />
      <ejb-relationship-role>
      <ejb-relationship-role-name>
      GroupHasUsers
      </ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>id</field-name>
      <column-name>GROUP_ID</column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>

      <ejb-relationship-role>
      <ejb-relationship-role-name>
      UsersInGroup
      </ejb-relationship-role-name>
      <key-fields />
      </ejb-relationship-role>
      </ejb-relation>

      I've put debug output into the EJB code and all the values appears to be OK before and after the ejbCreate method gets called. The ejbPostCreate method reports the expected Group ID. It seems that the GROUP_ID value is getting corrupted by the JBoss CMR functionality.

      I hope someone can shed some light on this as I'm running out of ideas. I'll report it as a bug, unless someone can shine the light ;-)

      Thanks in advance

      Roger