Details
-
Bug
-
Status: Resolved
-
Critical
-
Resolution: Works as Designed
-
1.2.1.RELEASE
-
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.