6 Replies Latest reply on Aug 30, 2002 9:44 AM by Carles Pairot

    Specified key was too long

    Carles Pairot Newbie

      Hi all,

      I am trying to deploy two CMP 2.0 entities which both have a String as primary key. I have a relationship between them and that means JBoss (3.0.1) is trying to create a new table containing both keys as a unique primary key. When deploying the entities I receive an exception like this:

      16:32:01,970 WARN [ServiceController] Problem starting service jboss.j2ee:servi
      ce=EJB,jndiName=ejb/botule/Role
      org.jboss.deployment.DeploymentException: Error while creating table; - nested t
      hrowable: (java.sql.SQLException: Invalid argument value: Specified key was too
      long. Max key length is 500)

      ...

      I suppose this is because the DB I am using (mySQL) does not support primary keys larger than 500 characters, and as JBoss maps Java Strings as a VARCHAR(255), that means I am beyond the limit: 255*2=510 chars.

      My question is: is there any way in JBoss to specify how the mapping of the fields to the database is done? I would like these 2 fields to be mapped as VARCHAR(100), for example.

      Thanks in advance.

      --

      Carles.

        • 1. Re: Specified key was too long
          Carles Pairot Newbie

          I have found that if I change the property:


          <java-type>java.lang.String</java-type>
          <jdbc-type>VARCHAR</jdbc-type>
          <sql-type>VARCHAR(250) BINARY</sql-type>


          from standardjbosscmp-jdbc.xml it works but this affects all string mappings that JBoss does. Is it possible to make this mapping at field method ?

          • 2. Re: Specified key was too long
            Carles Pairot Newbie

            Hi,

            For those of you who are interested in this topic, I have found a better solution: I have added my own database type mapping to jbosscmp-jdbc.xml specific file of my application. Now all java strings are mapped to Varchar(250) but this only affects my application instead of affecting all applications by modifying the standardjbosscmp-jdbc.xml file.

            Greetings,

            Carles.

            • 3. Re: Specified key was too long
              Carles Pairot Newbie

              Hi again,

              I am trying to map the primary key variable to a specific JDBC type and I am trying to do so by putting these lines within jbosscmp-jdbc.xml:

              ...
              <cmp-field>
              <field-name>id</field-name>
              <column-name>id</column-name>
              <sql-type>VARCHAR(100)</sql-type>
              </cmp-field>
              ...

              But when I deploy the entity bean, JBoss displays this error:

              14:11:44,707 ERROR [XmlFileLoader] File file:/C:/cygwin/home/pairot/jboss3/serve
              r/default/tmp/deploy/server/default/deploy/botule-ejb-test.jar/80.botule-ejb-tes
              t.jar!/META-INF/jbosscmp-jdbc.xml process error. Line: 107. Error message:
              org.xml.sax.SAXParseException: The element "cmp-field" does not accept "sql-type" here.
              at org.apache.crimson.parser.Parser2.error(Parser2.java:3160)
              at org.apache.crimson.parser.ValidatingParser$ChildrenValidator.consume(
              ValidatingParser.java:349)

              Isn't this the correct syntax or I am missing something? The jbosscmp-jdbc.xml file is automatically generated by XDoclet 1.2.

              Thanks in advance,

              Carles.

              • 4. Re: Specified key was too long
                Carles Pairot Newbie

                Hi again,

                I am trying to map the primary key variable to a specific JDBC type and I am trying to do so by putting these lines within jbosscmp-jdbc.xml:

                ...
                <cmp-field>
                <field-name>id</field-name>
                <column-name>id</column-name>
                <sql-type>VARCHAR(100)</sql-type>
                </cmp-field>
                ...

                But when I deploy the entity bean, JBoss displays this error:

                14:11:44,707 ERROR [XmlFileLoader] File file:/C:/cygwin/home/pairot/jboss3/serve
                r/default/tmp/deploy/server/default/deploy/botule-ejb-test.jar/80.botule-ejb-tes
                t.jar!/META-INF/jbosscmp-jdbc.xml process error. Line: 107. Error message:
                org.xml.sax.SAXParseException: The element "cmp-field" does not accept "sql-type" here.
                at org.apache.crimson.parser.Parser2.error(Parser2.java:3160)
                at org.apache.crimson.parser.ValidatingParser$ChildrenValidator.consume(
                ValidatingParser.java:349)

                Isn't this the correct syntax or I am missing something? The jbosscmp-jdbc.xml file is automatically generated by XDoclet 1.2.

                Thanks in advance,

                Carles.

                • 5. Re: Specified key was too long
                  Carles Pairot Newbie

                  Hi again,

                  I am trying to map the primary key variable to a specific JDBC type and I am trying to do so by putting these lines within jbosscmp-jdbc.xml:

                  ...
                  <cmp-field>
                  <field-name>id</field-name>
                  <column-name>id</column-name>
                  <sql-type>VARCHAR(100)</sql-type>
                  </cmp-field>
                  ...

                  But when I deploy the entity bean, JBoss displays this error:

                  14:11:44,707 ERROR [XmlFileLoader] File file:/C:/cygwin/home/pairot/jboss3/serve
                  r/default/tmp/deploy/server/default/deploy/botule-ejb-test.jar/80.botule-ejb-tes
                  t.jar!/META-INF/jbosscmp-jdbc.xml process error. Line: 107. Error message:
                  org.xml.sax.SAXParseException: The element "cmp-field" does not accept "sql-type" here.
                  at org.apache.crimson.parser.Parser2.error(Parser2.java:3160)
                  at org.apache.crimson.parser.ValidatingParser$ChildrenValidator.consume(
                  ValidatingParser.java:349)

                  Isn't this the correct syntax or I am missing something? The jbosscmp-jdbc.xml file is automatically generated by XDoclet 1.2.

                  Thanks in advance,

                  Carles.

                  • 6. Re: Specified key was too long
                    Carles Pairot Newbie

                    As usual, I answer myself again. Final solution:

                    ...
                    <cmp-field>
                    <field-name>id</field-name>
                    <column-name>id</column-name>
                    <jdbc-type>VARCHAR</jdbc-type>
                    <sql-type>VARCHAR(100)</sql-type>
                    </cmp-field>
                    ...

                    And it works perfectly.

                    Cheers,

                    Carles.