1 Reply Latest reply on Jan 5, 2005 1:04 PM by abcolson

    Data Type Mapping

    abcolson

      Greetings List,

      I am using jboss-4.0.0RC2 with MS Access. I had to create my own mappings in standardjbosscmp-jdbc.xml (If anyone knows of one that already exists that may solve alot of my problems).

      In the type mapping I have the defaults set up as

      <jbosscmp-jdbc>
      
       <defaults>
       <datasource>java:/DefaultDS</datasource>
       <datasource-mapping>MS ACCESS</datasource-mapping>
      
       <create-table>true</create-table>
       <remove-table>false</remove-table>
       <read-only>false</read-only>
       <read-time-out>300000</read-time-out>
       <row-locking>false</row-locking>
       <pk-constraint>true</pk-constraint>
       <fk-constraint>false</fk-constraint>
       <preferred-relation-mapping>foreign-key</preferred-relation-mapping>
       <read-ahead>
       <strategy>on-load</strategy>
       <page-size>1000</page-size>
       <eager-load-group>*</eager-load-group>
       </read-ahead>
       <list-cache-max>1000</list-cache-max>
       <clean-read-ahead-on-load>false</clean-read-ahead-on-load>
      
       <unknown-pk>
       <key-generator-factory>UUIDKeyGeneratorFactory</key-generator-factory>
       <unknown-pk-class>java.lang.String</unknown-pk-class>
       <jdbc-type>VARCHAR</jdbc-type>
       <sql-type>VARCHAR(32)</sql-type>
       </unknown-pk>
      
       <entity-command name="default"/>
       <ql-compiler>org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLCompiler</ql-compiler>
       </defaults>
      


      and in the type mapping section I have

      <type-mapping>
       <name>MS ACCESS</name>
      .
      .
      .
       <mapping>
       <java-type>java.lang.String</java-type>
       <jdbc-type>VARCHAR</jdbc-type>
       <sql-type>VARCHAR(255)</sql-type>
       </mapping>
      .
      .
       </type-mapping>
      


      Additionally, my msaccess-ds.xml file is

      <datasources>
      <local-tx-datasource>
      <jndi-name>DefaultDS</jndi-name>

      <!-- format of URL is "jdbc:odbc:DSNNAME" -->
      <connection-url>jdbc:odbc:EpidemiologyWebData</connection-url>


      <!--
      <connection-property name="SelectMethod">cursor</connection-property>
      -->

      <driver-class>sun.jdbc.odbc.JdbcOdbcDriver</driver-class>

      <user-name></user-name>
      <password></password>
      </local-tx-datasource>

      <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
      <metadata>
      <type-mapping>MS ACCESS</type-mapping>
      </metadata>

      </datasources>


      Upon startup I get the following error

      18:31:48,640 ERROR [EntityContainer] Starting failed jboss.j2ee:jndiName=ejb/UserLocal,service=EJB
      org.jboss.deployment.DeploymentException: Error while creating table complianceproject; - nested throwable: (java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Size of field 'name' is too long.)


      Looking in the odbc log I see

      tools.jar org.j e7c-878 EXIT SQLExecDirect with return code -1 (SQL_ERROR)
      HSTMT 04F42960
      UCHAR * 0x03F31410 [ -3] "CREATE TABLE complianceproject (name VARCHAR(256), deadline TIMESTAMP, instructions VARCHAR(256))\ 0"
      SDWORD -3

      DIAG [37000] [Microsoft][ODBC Microsoft Access Driver] Size of field 'name' is too long. (-1506)




      My question is why is this happening? It appears that I have set the max to be 255. Where else could the 256 be coming from?

      Thanks
      Tony

        • 1. Re: Data Type Mapping
          abcolson

          Here is a new twist.

          The reason my java.lang.String gets mapped to VARCHAR(256) and not VARCHAR(255) is because of some sort of Hypersonic dependancy, i.e. JBoss is pulling VARCHAR(256) mapping from the Hypersonic mappings instead of VARCHAR(255) from the MS ACCESS mapping.

          Example:

          1) I removed all the type-mapping elements from standardjbosscmp-jdbc.xml except for MS ACCESS...the result was a burp when JBoss tried to create my complianceproject table upon startup which complained about Hypersonic errors.

          2) I then added back in the Hypersonic type-mapping into standardjbosscmp-jdbc.xml and changed the java.lang.String mapping from VARCHAR(256) to VARCHAR(255)...the table was created fine.

          The question of the day is: Why is this happening?

          Where else does JBoss get db mapping information from? I removed standardjaws.xml (What is this for anyways?) from the conf directory and my table was still created fine.

          Any insight is appreciated.
          Tony