3 Replies Latest reply on Sep 13, 2007 1:07 PM by indyjones

    Seam Pros - Need your opinion...Date vs Long

      I have a POJO that needs to store date information.

      But, I don't want to store the Java type "Date" in my database, I prefer to store my date in the database as Java type "Long".

      This is all fine and good, but when i display this POJO, i dont want the Long number displayed for my date, I want a readable date format...

      Right now, I have 2 properties on my POJO...

      
       public Long getDate() { return date; }
       public void setDate(Long date) { this.date = date; }
      
       public Date getDateDisplay() { return datedisply; }
       public void setDateDisplay(Date datedisplay) { this.datedisplay = datedisplay; }
      
      


      I use one method to save to the database and the other in my JSF EL calls to display on a page.

      Is there a better way of doing this?

      Is there a JSF tag to convert a Long into a Date?

      Is there a way to have a property on my POJO without saving it to the database? (Right now i have 2 columns with the same data)

      Or, am I just doing this wrong?

      Thanks

      Indy


        • 1. Re: Seam Pros - Need your opinion...Date vs Long
          goku2

          Use

          @Basic
          @Temporal(TemporalType.TIMESTAMP)
          private Date someDate;
          


          It will store the timestamp and you could use the date class. I think it can work with Calendar too.

          If you want the time represented in milliseconds sine the Epoch(1/jan/1970) use the method .getTime() from the Date class.

          In your .xhtml use

          <h:outputText value="#{someBean.someDate}">
           <s:convertDateTime pattern="dd/MM/yyyy H:mm" />
          </h:outputText>
          


          to show the date.

          Hope this helps

          • 2. Re: Seam Pros - Need your opinion...Date vs Long
            matt.drees

            I'm fine with storing dates in the database. But if I had to store longs, I'd look into using Dates in my java object and mapping it to the database using a custom type. I haven't tried it, but I'm pretty sure that'd work.

            If you decide to stay with having two properties, mark the Date one @Transient, and it won't show up as a column.

            • 3. Re: Seam Pros - Need your opinion...Date vs Long

              Thanks for the info guys!!

              This helps a ton...

              Indy