glassfish
  1. glassfish
  2. GLASSFISH-20913

Persisting a temporaltype.Date or temporaltype.Time object requires refresh to get the proper value

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 4.0
    • Fix Version/s: None
    • Component/s: entity-persistence
    • Labels:
      None

      Description

      Given an entity

      @Entity
      public class PersistedBean {
      @Id @GeneratedValue private long id;

      @Temporal(TemporalType.DATE)
      private Date someDate;

      @Temporal(TemporalType.TIME)
      private Date someTime;

      @Temporal(TemporalType.TIMESTAMP)
      private Date someTimestamp;
      }

      And an SLSB

      @Stateless
      // @Interceptors(LoggingInterceptor.class)
      public class PersistedBeans {
      @PersistenceContext
      private EntityManager em;

      public PersistedBean getLatest()

      { final PersistedBean bean = em .createQuery( "select p from PersistedBean p order by p.someDate desc, p.id desc", PersistedBean.class).setFlushMode(FlushModeType.AUTO) .getResultList().get(0); // em.refresh(bean); return bean; }

      public void save(final PersistedBean bean)

      { em.persist(bean); }

      }

      performing the following call

      public PersistedBean helloJpaBean()

      { final PersistedBean bean = new PersistedBean(); bean.setSomeDate(new Date()); bean.setSomeTime(new Date()); bean.setSomeTimestamp(new Date()); bean.setMessage("Hello JPA" + new Date()); persistedBeans.save(bean); return persistedBeans.getLatest(); }

      Shows someDate and someTime with their time and date components respectively rather than the date only or time only portions.

      The database stores the data correctly.

      The work around at the moment is to do an em.refresh() on the retrieved result.

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Mitesh Meswani
            Reporter:
            atrajano
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: