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:


      <java-type>java.lang.Character</java-type>
      <jdbc-type>CHAR</jdbc-type>
      <sql-type>CHAR(1)</sql-type>


      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
      atement.java:1931)
      at oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedSt
      atement.java:2052)
      at org.jboss.resource.adapter.jdbc.local.LocalPreparedStatement.setObjec
      t(LocalPreparedStatement.java:607)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCUtil.setParameter(JDBCUtil.java:15
      6)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractCMPFieldBridge.setA
      rgumentParameters(JDBCAbstractCMPFieldBridge.java:283)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractCMPFieldBridge.setI
      nstanceParameters(JDBCAbstractCMPFieldBridge.java:262)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.insertEntity(J
      DBCCreateEntityCommand.java:192)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.execute(JDBCCr
      eateEntityCommand.java:131)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStor
      eManager.java:444)
      at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersisten
      ceManager.java:253)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.crea
      teEntity(CachedConnectionInterceptor.java:231)
      at org.jboss.ejb.EntityContainer.createLocalHome(EntityContainer.java:57
      9)
      at java.lang.reflect.Method.invoke(Native Method)
      at org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityC
      ontainer.java:1116)
      at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractIntercep
      tor.java:73)
      at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(Ent
      itySynchronizationInterceptor.java:230)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invo
      keHome(CachedConnectionInterceptor.java:176)
      at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInst
      anceInterceptor.java:134)
      at org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLockInte
      rceptor.java:79)
      at org.jboss.ejb.plugins.EntityCreationInterceptor.invokeHome(EntityCrea
      tionInterceptor.java:44)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte
      rceptor.java:98)

        • 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);

          ps.executeUpdate();


          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.
              Cheers

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

                Ok.
                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.