3 Replies Latest reply on Mar 23, 2002 5:01 PM by Viet

    java.sql.Timestamp not accepted as java.util.Date

    Viet Master

      Hi dudes,

      I have an bean with a java.util.Date cmp field using
      built in hsqldb.

      When I use the setter with an instance of Date,
      for instance Calendar.getInstance().getTime() that's
      fine.

      But if I do that bean.setDate(bean.getDate())
      there is a problem. I have an NumberFormatException
      thrown by hsqldb.

      In fact the getter method gives back an instance
      of java.sql.Timestamp which inherits from java.sql.Date.

      There should be have no problem, but that's not the case.
      The workaround I found is :

      temp = Calendar.getInstance();
      temp.setTime(bean.getDate());
      bean.setDate(temp.getTime());

      regards, Julien

      ps : in fact I don't do bean.setDate(bean.getDate())
      which seems very stupid, I manipulates several
      beans. That's a shortcut for the problem report.

        • 1. Re: java.sql.Timestamp not accepted as java.util.Date
          Dain Sundstrom Master

          You lost me.

          What version of JBoss are you using, and what is happing with the dates?

          • 2. Re: java.sql.Timestamp not accepted as java.util.Date
            Viet Master

            Hi Dain,

            I am working on it but that's very hard to figure out
            what exactly is happening.

            I am using latest cvs jboss3.0b2 with hsqldb bundled.

            Here is some information about what I have found
            at the moment :

            I have a CMP 2.0 bean with a java.util.Date field.
            I do a findBy on an instance, get the field
            to build another bean having a java.util.Date
            field too.

            When creating that bean the Date object is an instance
            of java.sql.Timestamp (toString says
            "2002-03-26 00:00:00.0")

            I have patched hsqldb jdbcPreparedStatement
            to have more informations when setObject
            is called.

            Set object is called by
            org.jboss...local.PreparedStatementInPool.setObject
            with that 3 parameters :

            1. 2
            2. an instance of java.sql.Timestamp ("2002-03-26
            00:00:00.0")
            3. 91

            and that raise a NumberFormatException in hsqldb code.

            I am goind to serahc more deeper but I feel
            I've reached my limit. I should dive
            in jboss code but there is overhead for me.

            BTW, I got precisely that exception:

            16:08:22,391 ERROR [BookingBean] Could not create entity
            java.lang.NumberFormatException: 26 00:00:00.0
            at java.lang.Integer.parseInt(Integer.java:423)
            at java.lang.Integer.parseInt(Integer.java:463)
            at java.sql.Date.valueOf(Date.java:91)
            at org.hsqldb.Column.convertString(Column.java:632)
            at org.hsqldb.Column.convertObject(Column.java:689)
            at org.hsqldb.jdbcPreparedStatement.setObject(jdbcPreparedStatement.java
            :592)
            at org.jboss.resource.adapter.jdbc.local.PreparedStatementInPool.setObje
            ct(PreparedStatementInPool.java:534)
            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:236)
            at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractCMPFieldBridge.setI
            nstanceParameters(JDBCAbstractCMPFieldBridge.java:215)
            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:376)
            at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersisten
            ceManager.java:239)
            at org.jboss.ejb.EntityContainer.createLocalHome(EntityContainer.java:56
            0)
            at java.lang.reflect.Method.invoke(Native Method)
            at org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityC
            ontainer.java:1059)
            at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractIntercep
            tor.java:73)
            at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(Ent
            itySynchronizationInterceptor.java:222)
            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.AbstractTxInterceptor.invokeNext(AbstractTxInte
            rceptor.java:98)
            at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep
            torCMT.java:167)
            at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.ja
            va:52)
            at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityIntercep
            tor.java:102)
            at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:1
            09)
            at org.jboss.ejb.EntityContainer.invokeHome(EntityContainer.java:468)
            at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.invokeHome(Base
            LocalContainerInvoker.java:243)
            at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker$HomeProxy.invok
            e(BaseLocalContainerInvoker.java:367)
            at $Proxy50.create(Unknown Source)
            at com.LaConcorde.knowledge.clerks.application.ApplicationClerkBean.sear
            chJob(ApplicationClerkBean.java:64)
            at java.lang.reflect.Method.invoke(Native Method)
            at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(S
            tatelessSessionContainer.java:648)
            at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(Stat
            elessSessionInstanceInterceptor.java:77)
            at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte
            rceptor.java:96)
            at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep
            torCMT.java:167)
            at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:6
            1)
            at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.
            java:127)
            at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:166)
            at org.jboss.ejb.StatelessSessionContainer.invoke(StatelessSessionContai
            ner.java:308)
            at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.invoke(BaseLoca
            lContainerInvoker.java:307)
            at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker$StatelessSessio
            nProxy.invoke(BaseLocalContainerInvoker.java:523)
            at $Proxy71.searchJob(Unknown Source)
            at com.LaConcorde.knowledge.dispatcher.MessageDispatcherBean.onMessage(M
            essageDispatcherBean.java:42)
            at java.lang.reflect.Method.invoke(Native Method)
            at org.jboss.ejb.MessageDrivenContainer$ContainerInterceptor.invoke(Mess
            ageDrivenContainer.java:430)
            at org.jboss.ejb.plugins.MessageDrivenInstanceInterceptor.invoke(Message
            DrivenInstanceInterceptor.java:88)
            at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte
            rceptor.java:96)
            at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep
            torCMT.java:167)
            at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:6
            1)
            at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.
            java:127)
            at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:166)
            at org.jboss.ejb.MessageDrivenContainer.invoke(MessageDrivenContainer.ja
            va:305)
            at org.jboss.ejb.plugins.jms.JMSContainerInvoker.invoke(JMSContainerInvo
            ker.java:625)
            at org.jboss.ejb.plugins.jms.JMSContainerInvoker$MessageListenerImpl.onM
            essage(JMSContainerInvoker.java:973)
            at org.jboss.jms.asf.StdServerSession.onMessage(StdServerSession.java:23
            4)
            at org.jboss.mq.SpyMessageConsumer.sessionConsumerProcessMessage(SpyMess
            ageConsumer.java:559)
            at org.jboss.mq.SpyMessageConsumer.addMessage(SpyMessageConsumer.java:37
            6)
            at org.jboss.mq.SpySession.run(SpySession.java:219)
            at org.jboss.jms.asf.StdServerSession.run(StdServerSession.java:173)
            at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExec
            utor.java:642)
            at java.lang.Thread.run(Thread.java:484)

            • 3. Re: java.sql.Timestamp not accepted as java.util.Date
              Viet Master

              OK Dain, I think I have more informations
              about that case.

              I have been able to reproduce that error outside
              the scope of my project on a little test case.
              (That was hard enough to catch where exactly
              it was)

              On that case I've one CMP bean with a PK and a java.util.Date field.

              That bean has a create method with that 2 fields
              and ejbCreate does set on the two abstracts setters.

              Instead of using an instance of java.util.Date
              I do that : time = new Timestamp(1017129600000L);

              And the problems appears again.

              In my project, I an getting a date field from
              one bean to build another and that what's happening
              exactly.

              I don't know from which layer the problem comes from :
              Jboss, hsql, sun ?

              Anyway, I have attached the little test case.
              Hope to have some information back from you.

              regards, Julien.