2 Replies Latest reply on Aug 8, 2006 11:25 AM by mailinator

    JBoss 3.2.8SP1/CMP/SQL TIME & DATETIME

    mailinator Novice

      I migrated an existing JBoss application to mySQL from MSSQL that has a DATETIME activityTime column in a specific table and a CMP EntityBean that uses the java.sql.Time to get and set values from that column.

      Now I am getting the following exception:
      javax.ejb.CreateException: Could not create entity:java.sql.SQLException: Data truncated for column 'activityTime' at row 1
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateCommand.performInsert(JDBCAbstractCreateCommand.java:339)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateCommand.execute(JDBCAbstractCreateCommand.java:150)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStoreManager.java:587)
      at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManager.java:226)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.createEntity(CachedConnectionInterceptor.java:282)
      at org.jboss.ejb.EntityContainer.createLocalHome(EntityContainer.java:587)
      at sun.reflect.GeneratedMethodAccessor617.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityContainer.java:1080)
      at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.java:103)
      at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(EntitySynchronizationInterceptor.java:219)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invokeHome(CachedConnectionInterceptor.java:227)
      at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.java:103)
      at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceInterceptor.java:112)
      at org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLockInterceptor.java:76)
      at org.jboss.ejb.plugins.EntityCreationInterceptor.invokeHome(EntityCreationInterceptor.java:43)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:105)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:348)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:159)
      at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:99)
      at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:135)
      at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invokeHome(ProxyFactoryFinderInterceptor.java:107)
      at org.jboss.ejb.EntityContainer.internalInvokeHome(EntityContainer.java:492)
      at org.jboss.ejb.Container.invoke(Container.java:743)
      at org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invokeHome(BaseLocalProxyFactory.java:362)
      at org.jboss.ejb.plugins.local.LocalHomeProxy.invoke(LocalHomeProxy.java:125)
      at $Proxy259.create(Unknown Source)
      ......


      After some Jboss debugging I noticed the following code in the org.jboss.ejb.plugins.cmp.jdbc.JDBCUtil.coerceToSQLType()

      if(value.getClass() == java.util.Date.class)
      {


      Since the value in my case is a java.sql.Time and not a Date the if evaluates to false and the value returned by this method is the Time object. Now shouldnt the if use instanceof instead of the == operator since Time is a subclass of Date?

      NOTE: I then realized that this code wasnt working in MSSQL. The difference there is that MSSQL was automatically coercing the value to a default Time value.