2 Replies Latest reply on Jul 18, 2004 4:46 PM by microbiotic

    loosing nanoseconds in timestamp after ejbStore

    microbiotic Newbie

      Hi all,

      I have a problem with storing sql.Timestamp fields. Every time after an ejbStore() the nanoseconds are thrown away for ever. Im using jboss 3.2.3 and a mysql 4 db. There are no additional mappings made - only using jboss default mappings.

      Can someone explain me this behavior ?
      Thanks in advance.

      Greets,
      Marcel

       /**
       * @see javax.ejb.EntityBean#ejbLoad()
       */
       public void ejbLoad() throws EJBException, RemoteException {
       log.debug("ejbLoad(): converting values.");
       Timestamp adate = getSQLActivationDate();
       Timestamp edate = getSQLExpirationDate();
       if (adate != null && edate != null) {
       log.debug("adate = " + adate.getTime() + "nanos: " + adate.getNanos());
       log.debug("edate = " + edate.getTime() + "nanos: " + adate.getNanos());
       }
       activationDate = convertSQLTimeStampToCalendar(adate);
       expirationDate = convertSQLTimeStampToCalendar(edate);
      
       if (activationDate != null && expirationDate != null) {
       log.debug("activationDate = " + activationDate.getTimeInMillis());
       log.debug("expirationDate = " + expirationDate.getTimeInMillis());
       }
       }
      
       /**
       * @see javax.ejb.EntityBean#ejbStore()
       */
       public void ejbStore() throws EJBException, RemoteException {
       log.debug("ejbStore(): converting values.");
       if (activationDate != null && expirationDate != null) {
       log.debug("activationDate = " + activationDate.getTimeInMillis());
       log.debug("expirationDate = " + expirationDate.getTimeInMillis());
       }
       Timestamp adate = convertCalendarToSQLTimeStamp(activationDate);
       Timestamp edate = convertCalendarToSQLTimeStamp(expirationDate);
       setSQLActivationDate(adate);
       setSQLExpirationDate(edate);
       if (adate != null && edate != null) {
       log.debug("adate = " + adate.getTime());
       log.debug("edate = " + edate.getTime());
       }
       }
      ...
      
       private Calendar convertSQLTimeStampToCalendar(Timestamp t) {
       Calendar date = null;
       if (t != null) {
       date = Calendar.getInstance();
       date.setTimeInMillis(t.getTime() + t.getNanos() / 1000000);
       }
       return date;
       }
      
       private Timestamp convertCalendarToSQLTimeStamp(Calendar c) {
       Timestamp t = null;
       if (c != null) {
       t = new Timestamp(c.getTimeInMillis());
       }
       return t;
       }
      


      output:
      21:48:59,396 DEBUG [PollingCycleBean:534] ejbStore(): converting values.
      21:48:59,406 DEBUG [PollingCycleBean:536] activationDate = 1086295664847
      21:48:59,406 DEBUG [PollingCycleBean:537] expirationDate = 1117831664847
      21:48:59,626 DEBUG [PollingCycleBean:544] adate = 1086295664847
      21:48:59,626 DEBUG [PollingCycleBean:545] edate = 1117831664847
      21:49:04,453 DEBUG [PollingCycleBean:514] ejbLoad(): converting values.
      21:49:04,453 DEBUG [PollingCycleBean:518] adate = 1086295664000nanos: 0
      21:49:04,453 DEBUG [PollingCycleBean:519] edate = 1117831664000nanos: 0
      21:49:04,453 DEBUG [PollingCycleBean:525] activationDate = 1086295664000
      21:49:04,453 DEBUG [PollingCycleBean:526] expirationDate = 1117831664000