5 Replies Latest reply on Jul 15, 2002 3:02 PM by dsundstrom

    JBoss fails to create table with compound primary key

    rune

      Hello
      We have an entity bean with a compound primary key which JBoss fails to create table for during deployment. We are using JBoss 3.0.0, jdk 1.4.0 and MySql. The ejb-jar.xml section for this entity bean looks like this:


      <![CDATA[]]>
      <ejb-name>Role</ejb-name>
      <local-home>com.mobinor.j2ee.userorg.interfaces.RoleLocalHome</local-home>
      com.mobinor.j2ee.userorg.interfaces.RoleLocal
      <ejb-class>com.mobinor.j2ee.userorg.ejb.RoleCMP</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>com.mobinor.j2ee.userorg.interfaces.RolePK</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>Role</abstract-schema-name>
      <cmp-field >
      <![CDATA[Role name.]]>
      <field-name>role</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[Role group.]]>
      <field-name>rolegroup</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[User name.]]>
      <field-name>username</field-name>
      </cmp-field>


      The jbosscmp-jdbc.xml section looks like this:


      <ejb-name>Role</ejb-name>
      <create-table>true</create-table>
      <cmp-field>
      <field-name>role</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>rolegroup</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>username</field-name>
      </cmp-field>


      The error message we get during deployment is:

      08:47:39,542 WARN [NestedThrowable] Duplicate throwable nesting of same base type: class org.jboss.deployment.DeploymentException is assignable from: class org.jboss.deployment.DeploymentException
      08:47:39,544 ERROR [MainDeployer] could not start deployment: file:/home/kommuneinfo/jboss-3.0.0_tomcat-4.0.3/server/default/deploy/userorg.jar
      org.jboss.deployment.DeploymentException: Could not deploy file:/home/kommuneinfo/jboss-3.0.0_tomcat-4.0.3/server/default/deploy/userorg.jar; - nested throwable: (org.jboss.deployment.DeploymentException: Error while creating table; - nested throwable: (java.sql.SQLException: Invalid argument value: Specified key was too long. Max key length is 500))
      at org.jboss.ejb.EJBDeployer.start(EJBDeployer.java:413)
      at org.jboss.deployment.MainDeployer.start(MainDeployer.java:678)
      at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:513)
      at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:481)
      at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:491)
      at org.jboss.util.jmx.MBeanProxy.invoke(MBeanProxy.java:174)
      at $Proxy4.deploy(Unknown Source)
      at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:405)
      at org.jboss.deployment.scanner.URLDeploymentScanner.scanDirectory(URLDeploymentScanner.java:586)
      at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:465)
      at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:202)
      at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:191)
      Caused by: org.jboss.deployment.DeploymentException: Error while creating table; - nested throwable: (java.sql.SQLException: Invalid argument value: Specified key was too long. Max key length is 500)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStartCommand.createTable(JDBCStartCommand.java:190)

      Anyone have any idea ?

      Regards
      Rune Hamnvik
      Mobinor AS
      Norway

        • 1. Re: JBoss fails to create table with compound primary key
          dsundstrom

          You should be getting a nested exception printed. If you are what is the nested exception?

          Also what is the the create table statement? This looks like a database error, meaning you database does not like the autogenerated sql because of some internal db constraint. I suggest you attempt to execute the create table statement directly in your database.

          • 2. Re: JBoss fails to create table with compound primary key
            rune

            Hello
            Thank you for your quick answer.

            I tried to execute the create statement directly into mysql, and the statement failed. The create statement is as follows:
            mysql> CREATE TABLE Role (role VARCHAR(255) BINARY NOT NULL, username VARCHAR(255) BINARY NOT NULL,
            -> rolegroup VARCHAR(255) BINARY, CONSTRAINT pk_Role PRIMARY KEY (role, username));

            And the error message was: ERROR 1071: Specified key was too long. Max key length is 500

            Any idea what is wrong with this create statement ?

            Rune Hamnvik

            • 3. Re: JBoss fails to create table with compound primary key
              rune

              Hello
              Thank you for your quick answer.

              I tried to execute the create statement directly into mysql, and the statement failed. The create statement is as follows:
              mysql> CREATE TABLE Role (role VARCHAR(255) BINARY NOT NULL, username VARCHAR(255) BINARY NOT NULL,
              -> rolegroup VARCHAR(255) BINARY, CONSTRAINT pk_Role PRIMARY KEY (role, username));

              And the error message was: ERROR 1071: Specified key was too long. Max key length is 500

              Any idea what is wrong with this create statement ?

              Rune Hamnvik

              • 4. Re: JBoss fails to create table with compound primary key
                rune

                Hello
                Thank you for your quick answer.

                I tried to execute the create statement directly into mysql, and the statement failed. The create statement is as follows:
                mysql> CREATE TABLE Role (role VARCHAR(255) BINARY NOT NULL, username VARCHAR(255) BINARY NOT NULL,
                -> rolegroup VARCHAR(255) BINARY, CONSTRAINT pk_Role PRIMARY KEY (role, username));

                And the error message was: ERROR 1071: Specified key was too long. Max key length is 500

                Any idea what is wrong with this create statement ?

                Rune Hamnvik

                • 5. Re: JBoss fails to create table with compound primary key
                  dsundstrom

                  My guess is that you database can not have a primary key longer then 500 bytes. If you database uses 2 bytes for a character, which is fairly common, the VARCHAR(255) is a 510 byte pk. Try changing role column VARCHAR(200).