4 Replies Latest reply on May 16, 2002 6:15 AM by Tim Fox

    unable to map Character type too

    Tim Fox Master

      Hi All-

      Trying to map attribute of type java.lang.Character to Oracle 8.1.7 char(1) column:

      Using 3.0rc2

      Mapping extract is:


      this gives me the following exception when I tried to create() a new instance in the db:

      I've previously had problems with the primitive char type (hence my previous bug report), and now I am getting this.
      I would be really interested in knowing how anyone has got this to work, since I certainly can't work it out!

      (I'm also unable to persist BigDecimal and booleans, but that's a different story !)

      15:33:49,818 ERROR [TesterEJB] Could not create entity
      java.lang.ClassCastException: java.lang.Character
      at oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedSt
      at oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedSt
      at org.jboss.resource.adapter.jdbc.local.LocalPreparedStatement.setObjec
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCUtil.setParameter(JDBCUtil.java:15
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractCMPFieldBridge.setA
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractCMPFieldBridge.setI
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.insertEntity(J
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.execute(JDBCCr
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStor
      at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersisten
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.crea
      at org.jboss.ejb.EntityContainer.createLocalHome(EntityContainer.java:57
      at java.lang.reflect.Method.invoke(Native Method)
      at org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityC
      at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractIntercep
      at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(Ent
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invo
      at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInst
      at org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLockInte
      at org.jboss.ejb.plugins.EntityCreationInterceptor.invokeHome(EntityCrea
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte

        • 1. Re: unable to map Character type too
          Tim Fox Master

          I've created a test program that does some raw JDBC and tries to set a char field using setObject() (which is was jboss cmp does):

          PreparedStatement ps =
          conn.prepareStatement("insert into tester(id, charfield) " +
          "values (?)");

          ps.setObject(1, new Character('C'), java.sql.Types.CHAR);


          This always falls over (i've tried with Oracle 8 both thin and OCI drivers).

          It seems that whatever value (and I've tried them all) for the SQL Type results in a ClassCastException.

          The JBoss CMP code seems to always use the setObject method to set the preparedstatement fields ie it leaves the conversion up to the driver giving just a hint with the sql type parameter.

          Unless I'm mistaken, this means you can't map Character (or char) attributes using JBoss and at least the OCI and thin drivers.

          I guess this is going to be a big problem for Oracle users.

          A suggestion would be to do an explicit conversion in the JDBCUtil class.

          eg convert it to a string and set it as that on the preparedstatement (I notice that char fields are already read as strings).

          • 2. Re: unable to map Character type too
            Dain Sundstrom Master

            I bet you that if you change the JDBC type to VARCHAR it will work fine. If it does, post a bug report with the change for the standardjbosscmp-jdbc.xml file and I'll make the change.

            • 3. Re: unable to map Character type too
              Tim Fox Master

              Hi Dain-
              I'm 90% sure I've already tried that...
              I'll try it again tomorrow anyway, and if no joy, I'll post a bug report.

              • 4. Re: unable to map Character type too
                Tim Fox Master

                I have tried setObject() setting Character on preparedstatement with all 27-odd sql types available in JDK 1.3, including varchar and none allow it.
                Database column is char(1)
                Database is Oracle 8.1.7
                I have tried with Oracle's own thin and oci drivers for 8.1.
                I shall file a bug report now.