2 Replies Latest reply on Dec 4, 2002 9:43 AM by moskvich

    Best practice for Date in CMP Beans

    ivylim

      Hi people,

      My current env is JBoss 3.0 on Windows 2000 with Oracle 8i thin JDBC.

      My simple CMP bean (used in the Quick Start Guide template) works provided I removed the java.sql.Date attribute. Here's the code: -


      /**
      * @return Returns the creation date of this TestEntity
      *
      * @ejb:persistent-field
      *
      * @jboss:column-name name="Creation_Date"
      **/
      public abstract java.sql.Date getCreationDate();

      /**
      * Specify the creation date of this TestEntity
      *
      * @param pCreationDate Date of the creation of this TestEntity
      **/
      public abstract void setCreationDate( java.sql.Date pCreationDate );



      Here's the exception:-

      15:50:15,118 ERROR [MainDeployer] could not start deployment: file:/D:/jboss-3.0.0_tomcat-4.0.3/serv
      er/default/deploy/ejb-test.jar
      org.jboss.deployment.DeploymentException: Could not deploy file:/D:/jboss-3.0.0_tomcat-4.0.3/server/
      default/deploy/ejb-test.jar; - nested throwable: (org.jboss.deployment.DeploymentException: Error wh
      ile creating table; - nested throwable: (java.sql.SQLException: ORA-00902: invalid datatype
      ))
      at org.jboss.ejb.EJBDeployer.start(EJBDeployer.java:413)
      at org.jboss.deployment.MainDeployer.start(MainDeployer.java:678)
      at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:513)
      at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:481)
      at java.lang.reflect.Method.invoke(Native Method)
      at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284
      )
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:491)
      at org.jboss.util.jmx.MBeanProxy.invoke(MBeanProxy.java:174)
      at $Proxy4.deploy(Unknown Source)
      at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:405)
      at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:515)
      at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploym
      entScanner.java:202)
      at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeployme
      ntScanner.java:191)
      + nested throwable:
      org.jboss.deployment.DeploymentException: Error while creating table; - nested throwable: (java.sql.
      SQLException: ORA-00902: invalid datatype
      )
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStartCommand.createTable(JDBCStartCommand.java:190)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStartCommand.execute(JDBCStartCommand.java:84)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.start(JDBCStoreManager.java:383)
      at org.jboss.ejb.plugins.CMPPersistenceManager.start(CMPPersistenceManager.java:198)
      at org.jboss.ejb.EntityContainer.start(EntityContainer.java:376)
      ....



      HOWEVER, if I use java.util.Date, it works! Is this a bug with Oracle thin JDBC, JBoss, or is it something that I can do?

      What's the best practice for date/time attribute anyway?

      Thank you.

        • 1. Re: Best practice for Date in CMP Beans
          scoy

          I think this has been fixed in more recent JBoss 3.0x releases. You should try the latest.

          I suspect the mapping for java.sql.Date was missing from standardjbosscmp-jdbc.xml in JBoss 3.0.0, but I can't recall exactly.

          Best practice for date/times depends upon your database implementation and your business requirements. For instance, Oracle 8 does not have a native DATETIME type (although Oracle 9 has). A consequence of this is that you cannot reliably store/retrieve java.util.Date from Oracle without losing millisecond granularity.

          Steve

          • 2. Re: Best practice for Date in CMP Beans
            moskvich

            Ivy, specify the field type explicitly in the jbosscmp-jdbc.xml by tags <jdbc-type> and <sql-type> (I suppose name of the filed in the your DB is creation_date):

            <cmp-field>
            <field-name>creationDate</field-name>
            <column-name>creation_date</column-name>
            <jdbc-type>DATE</jdbc-type>
            <sql-type>DATE</sql-type>
            </cmp-field>

            Rebuild and redeploy your EJB and try to call method setCreationDate again.

            Does it work for you ?