Uploaded image for project: 'Spring Roo'
  1. Spring Roo
  2. ROO-3157

Wrong TemporalType annotation on field

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Critical
    • Resolution: Works as Designed
    • Affects Version/s: 1.2.1.RELEASE
    • Fix Version/s: 1.2.2.RELEASE
    • Component/s: @ CORE, JSF
    • Labels:
      None

      Description

      Here's script:

      project --projectName prototype --topLevelPackage com.roo.bug
      jpa setup --provider HIBERNATE --database HYPERSONIC_IN_MEMORY
      entity jpa --class ~.domain.DateObject --equals
      field string --fieldName title
      field date --fieldName someDate --type java.util.Date
      entity jpa --class ~.domain.ReferenceObject --equals
      field date --fieldName someOtherDate --type java.util.Date
      field string --fieldName title
      field set --fieldName dateObject --type ~.domain.DateObject --fetch EAGER --class ~.domain.ReferenceObject
      web jsf setup
      web jsf all --package ~.web

      When you create two DateObject instances with some dates set, then create a ReferenceObject with references to those DateObject instances, you'll get a JSF error stating that you chose wrong objects.

      "createForm:dateObjectCreateInput: Validation Error: Value is not valid"

      The reason is that JSF compares those objects using their equals methods. One object has a java.sql.Timestamp, while the other has a java.util.Date. The error happens because those two types are not equal.

      Solution:

      This part of the script:

      field date --fieldName someDate --type java.util.Date

      Generates this source:

      @Temporal(TemporalType.TIMESTAMP)
      @DateTimeFormat(style = "M-")
      private Date someDate;

      If we change it to:

      @Temporal(TemporalType.DATE) // N.B. now DATE
      @DateTimeFormat(style = "M-")
      private Date someDate;

      ... it works.

        Attachments

          Activity

            People

            Assignee:
            stewarta Alan Stewart
            Reporter:
            mc MC
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: