1 Reply Latest reply on Mar 8, 2006 10:32 PM by peixubin peixubin

    store string and Timestamp data into oracle ,error?

    peixubin peixubin Newbie


      I writen an entity bean,it have a Long key field,a String field,a Timestamp field...

      In my session bean ,I create a entity in a interface function createBug,update the String filed value and Timestamp field value in other function updateBug.

      I found the String field value is error,I update the value to "a_yyb", but the value in oracle database is not "a_yyb"!!!


      Then I change the Timestamp field type to java.sql.Date ,I found String value is correct.


      It is a jboss bug? or oracle bug? or jdk bug?

      evironment:
      os:
      debian-sarge,kernel:2.6.14.3
      java:
      jrockit-j2sdk1.4.2_05,jboss-3.2.7 or jboss-3.2.8.SP1,oracle jdbc driver:ojdbc14.jar
      database:
      oracle8.1.7


      entity bean code:

      package ydxt.ejb.entity;

      /**

      * This class is part of Middlegen airlines, and it is
      * a CMP EJB accessing the TESTBUG table.
      *
      * @ejb:permission role-name="PUBLIC"
      * @jboss:create-table create="true"
      * @jboss:remove-table remove="false"
      * @ejb:transaction type="Required"
      * @ejb.persistence table-name="TESTBUG"
      * @jboss.table-name table-name="TESTBUG"
      * @jboss.container-configuration name="custom container"
      * @comment TESTBUG have pk column
      * @ejb.value-object
      * @author Middlegen
      *
      * @ejb.bean
      * type="CMP"
      * cmp-version="2.x"
      * name="TestBug"
      * local-jndi-name="ejb/bug/TestBugLocalHome"
      * view-type="local"
      *
      * @ejb.finder
      * signature="java.util.Collection findAll()"
      * result-type-mapping="Local"
      * method-intf="LocalHome"
      * query="SELECT OBJECT(o) FROM TestBug o"
      * description="Find all entities."
      *
      * @ejb.persistence table-name="TESTBUG"
      * @ejb.transaction type="Required"
      *
      *
      */
      public abstract class TestBugBean
      implements javax.ejb.EntityBean {
      /**
      * Returns the pkid
      *
      * @return the pkid
      *
      * @ejb.pk-field
      * @ejb.interface-method view-type="local"
      * @ejb.persistent-field
      * @ejb.persistence column-name="PKID"
      */
      public abstract java.lang.Long getPkid();

      /**
      * Sets the pkid
      *
      * @param pkid the new pkid value
      */
      public abstract void setPkid(java.lang.Long pkid);

      /**
      * Returns the sqr
      *
      * @return the sqr
      *
      * @ejb.interface-method view-type="local"
      * @ejb.persistent-field
      * @ejb.persistence column-name="SQR"
      */
      public abstract java.lang.String getSqr();


      /**
      * Sets the sqr
      *
      * @param sqr the new sqr value
      * @ejb.interface-method view-type="local"
      */

      public abstract void setSqr(java.lang.String sqr);



      /**
      * Returns the sqsl
      *
      * @return the sqsl
      *
      * @ejb.interface-method view-type="local"
      * @ejb.persistent-field
      * @ejb.persistence column-name="SQSL"
      */
      public abstract java.lang.Long getSqsl();

      /**
      * Sets the sqsl
      *
      * @param sqsl the new sqsl value
      * @ejb.interface-method view-type="local"
      */
      public abstract void setSqsl(java.lang.Long sqsl);
      /**
      * Returns the sqk
      *
      * @return the sqk
      *
      * @ejb.interface-method view-type="local"
      * @ejb.persistent-field
      * @ejb.persistence column-name="SQK"
      */
      public abstract java.lang.Long getSqk();

      /**
      * Sets the sqk
      *
      * @param sqk the new sqk value
      * @ejb.interface-method view-type="local"
      */
      public abstract void setSqk(java.lang.Long sqk);



      /**
      * Returns the spr
      *
      * @return the spr
      *
      * @ejb.interface-method view-type="local"
      * @ejb.persistent-field
      * @ejb.persistence column-name="SPR"
      */
      public abstract java.lang.String getSpr();

      /**
      * Sets the spr
      *
      * @param spr the new spr value
      * @ejb.interface-method view-type="local"
      */
      public abstract void setSpr(java.lang.String spr);

      /**
      * Returns the spsl
      *
      * @return the spsl
      *
      * @ejb.interface-method view-type="local"
      * @ejb.persistent-field
      * @ejb.persistence column-name="SPSL"
      */
      public abstract java.lang.Long getSpsl();
      /**
      * Sets the spsl
      *
      * @param spsl the new spsl value
      * @ejb.interface-method view-type="local"
      */
      public abstract void setSpsl(java.lang.Long spsl);


      /**
      * Returns the fylx
      *
      * @return the fylx
      *
      * @ejb.interface-method view-type="local"
      * @ejb.persistent-field
      * @ejb.persistence column-name="FYLX"
      */
      public abstract java.lang.Long getFylx();

      /**
      * Sets the fylx
      *
      * @param fylx the new fylx value
      * @ejb.interface-method view-type="local"
      */
      public abstract void setFylx(java.lang.Long fylx);

      /**
      * Returns the spsj
      *
      * @return the spsj
      *
      * @ejb.interface-method view-type="local"
      * @ejb.persistent-field
      * @ejb.persistence column-name="SPSJ"
      */
      public abstract java.sql.Timestamp getSpsj();

      /**
      * Sets the spsj
      *
      * @param spsj the new spsj value
      * @ejb.interface-method view-type="local"
      */
      public abstract void setSpsj(java.sql.Timestamp spsj);

      /**
      * Returns the sqsj
      *
      * @return the sqsj
      *
      * @ejb.interface-method view-type="local"
      * @ejb.persistent-field
      * @ejb.persistence column-name="SQSJ"
      */
      public abstract java.sql.Timestamp getSqsj();

      /**
      * Sets the sqsj
      *
      * @param sqsj the new sqsj value
      * @ejb.interface-method view-type="local"
      */
      public abstract void setSqsj(java.sql.Timestamp sqsj);

      /**
      * Returns the lysj
      *
      * @return the lysj
      *
      * @ejb.interface-method view-type="local"
      * @ejb.persistent-field
      * @ejb.persistence column-name="LYSJ"
      */
      public abstract java.sql.Timestamp getLysj();

      /**
      * Sets the lysj
      *
      * @param lysj the new lysj value
      * @ejb.interface-method view-type="local"
      */
      public abstract void setLysj(java.sql.Timestamp lysj);

      /**
      * Returns the zt
      *
      * @return the zt
      *
      * @ejb.interface-method view-type="local"
      * @ejb.persistent-field
      * @ejb.persistence column-name="ZT"
      */
      public abstract java.lang.Long getZt();

      /**
      * Sets the zt
      *
      * @param zt the new zt value
      * @ejb.interface-method view-type="local"
      */
      public abstract void setZt(java.lang.Long zt);

      /**
      * Returns the bfyy
      *
      * @return the bfyy
      *
      * @ejb.interface-method view-type="local"
      * @ejb.persistent-field
      * @ejb.persistence column-name="BFYY"
      */
      public abstract java.lang.Long getBfyy();

      /**
      * Sets the Bfyy
      *
      * @param bfyy the new bfyy value
      * @ejb.interface-method view-type="local"
      */
      public abstract void setBfyy(java.lang.Long bfyy);

      /**
      * Returns the ysr
      *
      * @return the ysr
      *
      * @ejb.interface-method view-type="local"
      * @ejb.persistent-field
      * @ejb.persistence column-name="YSR"
      */
      public abstract java.lang.String getYsr();

      /**
      * Sets the ysr
      *
      * @param ysr the new ysr value
      * @ejb.interface-method view-type="local"
      */
      public abstract void setYsr(java.lang.String ysr);

      /**
      * Returns the spyj
      *
      * @return the spyj
      *
      * @ejb.interface-method view-type="local"
      * @ejb.persistent-field
      * @ejb.persistence column-name="SPYJ"
      */
      public abstract java.lang.String getSpyj();

      /**
      * Sets the spyj
      *
      * @param spyj the new spyj value
      * @ejb.interface-method view-type="local"
      */
      public abstract void setSpyj(java.lang.String spyj);

      /**
      * Returns the isty
      *
      * @return the isty
      *
      * @ejb.interface-method view-type="local"
      * @ejb.persistent-field
      * @ejb.persistence column-name="ISTY"
      */
      public abstract java.lang.Long getIsty();

      /**
      * Sets the isty
      *
      * @param isty the new isty value
      * @ejb.interface-method view-type="local"
      */
      public abstract void setIsty(java.lang.Long isty);


      /**
      * Returns the sqlb
      *
      * @return the sqlb
      *
      * @ejb.interface-method view-type="local"
      * @ejb.persistent-field
      * @ejb.persistence column-name="SQLB"
      */
      public abstract java.lang.Long getSqlb();

      /**
      * Sets the sqlb
      *
      * @param sqsl the new sqlb value
      * @ejb.interface-method view-type="local"
      */
      public abstract void setSqlb(java.lang.Long sqlb);

      /**
      * This create method takes only mandatory (non-nullable) parameters.
      *
      * When the client invokes a create method, the EJB container invokes he ejbCreate method.
      * Typically, an ejbCreate method in an entity bean performs the following tasks:
      *
      * Inserts the entity state into the database.
      * Initializes the instance variables.
      * Returns the primary key.
      *
      *
      * @return the primary key of the new instance
      *
      * @ejb.create-method
      */

      public ydxt.ejb.interfaces.TestBugPK ejbCreate(java.lang.Long pkid) throws javax.ejb.CreateException {
      setPkid(pkid);
      return null;
      }

      /**
      * The container invokes this method immediately after it calls ejbCreate.
      *
      */

      public void ejbPostCreate(java.lang.Long pkid ) throws javax.ejb.CreateException {
      // Set CMR fields
      }
      /**
      *
      */
      public abstract ydxt.ejb.interfaces.TestBugData getTestBugData();

      /**
      *
      *
      * @ejb.interface-method view-type="local"
      */
      public Object getData(){
      return getTestBugData();
      }
      }



      the sessionbean code:

      package ydxt.ejb.session;

      import java.rmi.RemoteException;
      import java.util.ArrayList;
      import java.util.Collection;
      import java.util.Collections;
      import java.util.Iterator;

      import javax.ejb.EJBException;
      import javax.ejb.FinderException;
      import javax.ejb.SessionBean;
      import javax.ejb.SessionContext;
      import javax.naming.NamingException;

      import ydxt.ejb.interfaces.*;
      import ydxt.ejb.support.EJBUtil;
      import ydxt.ejb.support.SessionSupport;
      import org.apache.commons.beanutils.PropertyUtils;
      import javax.ejb.CreateException;
      import javax.ejb.RemoveException;

      /**
      * @author peixubin
      * @ejb:bean type="Stateless"
      * name="BugManagerEJB"
      * jndi-name="BugManager"
      * transaction-type="Container"
      *
      * @ejb:transaction type="Required"
      * @ejb:permission role-name="PUBLIC"
      * @ejb.home extends="javax.ejb.EJBHome" local-extends="javax.ejb.EJBLocalHome"
      * @ejb.interface extends="javax.ejb.EJBObject"
      * local-extends="javax.ejb.EJBLocalObject"
      *
      * @ejb:ejb-ref ejb-name="TestBug" view-type="local" ref-name="ejb/bug"
      */
      public class BugManagerBean extends SessionSupport {

      TestBugLocalHome home = null;

      /**
      * @throws RemoteException
      * @throws FinderException
      * @ejb:interface-method view-type="remote"
      */
      public Object createBug(Object o)
      throws RemoteException, FinderException,CreateException {
      Long pkid=null;
      try {
      pkid=(Long)PropertyUtils.getProperty(o,"pkid");
      } catch (Exception e) {
      throw new FinderException(e.getMessage());
      }
      return getHome().create(pkid).getPkid();

      }


      /**
      * @throws RemoteException
      * @throws FinderException
      * @throws NamingException
      * @ejb:interface-method view-type="remote"
      */
      public Object updateBug(Object o)
      throws RemoteException, FinderException {
      Long pkid=null;
      String spr=null;
      String spyj=null;
      try {
      pkid=(Long)PropertyUtils.getProperty(o,"pkid");
      spr=(String)PropertyUtils.getProperty(o,"spr");
      } catch (Exception e) {
      throw new FinderException(e.getMessage());
      }

      try {
      TestBugLocal bug = getHome().findByPrimaryKey(new TestBugPK(pkid));
      bug.setSpr(spr);
      bug.setSpsj(new java.sql.Timestamp(new java.util.Date().getTime()));
      return bug.getPkid();
      } catch (Exception e) {
      ctx.setRollbackOnly();
      throw new FinderException(e.getMessage());
      }

      }

      /**
      * @throws RemoteException
      * @throws FinderException
      * @throws NamingException
      * @ejb:interface-method view-type="remote"
      */
      public void removeBug(Object o)
      throws RemoteException, FinderException,RemoveException {
      Long pkid=null;
      try {
      pkid=(Long)PropertyUtils.getProperty(o,"pkid");
      } catch (Exception e) {
      throw new FinderException("pkid is null");
      }
      getHome().findByPrimaryKey(new TestBugPK(pkid)).remove();

      }


      /**
      * Describe getBug method here.
      * @ejb:interface-method view-type="remote"
      * @param o an Object value
      * @return an Object value
      * @exception RemoteException if an error occurs
      * @exception FinderException if an error occurs
      */
      public Object getBug(Object o) throws RemoteException, FinderException {
      Long pkid=null;
      try {
      pkid=(Long)PropertyUtils.getProperty(o,"pkid");
      } catch (Exception e) {
      throw new FinderException("pkid is null");
      }
      return getHome().findByPrimaryKey(new TestBugPK(pkid)).getData();
      }


      /**
      * @return TestBugLocalHome
      */
      public TestBugLocalHome getHome() throws EJBException {
      try {
      if (home == null)
      home = (TestBugLocalHome) EJBUtil.lookup("java:comp/env/ejb/bug");

      } catch (Exception e) {
      throw new EJBException(e);
      }
      return home;
      }

      }



      the testPrepare testcase:
      ...
      public void testInit() throws Exception {
      BugManagerEJB manager=BugManagerEJBUtil.getHome().create();
      Map map=new HashMap();
      map.put("pkid",new Long(1));
      manager.createBug(map);
      map.put("spr","a_yyb");
      manager.updateBug(map);
      }
      ...

      the testBugTest testcase:

      public void testCheckData() throws Exception {
      BugManagerEJB manager=BugManagerEJBUtil.getHome().create();
      Map map=new HashMap();
      map.put("pkid",new Long(1));
      TestBugData bug=(TestBugData)manager.getBug(map);
      assertEquals("a_yyb",bug.getSpr());
      log.info("bug={"+bug+"}");
      }


      in shell :
      pxb@ygs-xxk-pxb$ ant test.prepare
      Buildfile: build.xml

      test.prepare:
      [junit] Running ydxt.ejb.test.TestPrepare
      [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.415 sec
      [junit] Testsuite: ydxt.ejb.test.TestPrepare
      [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.415 sec

      [junit] Testcase: testInit took 0.412 sec

      pxb@ygs-xxk-pxb$ ant test.ejb
      Buildfile: build.xml

      test.ejb:
      [junit] Running ydxt.ejb.test.TestBugTest
      [junit] Tests run: 1, Failures: 1, Errors: 0, Time elapsed: 0.352 sec
      [junit] Testsuite: ydxt.ejb.test.TestBugTest
      [junit] Tests run: 1, Failures: 1, Errors: 0, Time elapsed: 0.352 sec

      [junit] Testcase: testCheckData took 0.348 sec
      [junit] FAILED
      [junit] expected:<a_yyb> but was:<??yb>
      [junit] junit.framework.AssertionFailedError: expected:<a_yyb> but was:<??yb>
      [junit] at ydxt.ejb.test.TestBugTest.testCheckData()V(TestBugTest.java:29)
      ...