0

I am not able to check the equality of two dates in JPA. The comparison below works fine until I add the date of Birth. I am not sure if my JPQL is correct:

  TypedQuery<Applicant>  query = em.createQuery("select app "
                + "from Applicant app where "
                + "app.firstName = :firstName AND app.middleName = :middleName "
                + "AND app.lastName = :lastName" 
                +" AND app.dob = :dateOfBirth", Applicant.class);

            query.setParameter("firstName", searchableApplicant.getFirstName().trim());
            query.setParameter("middleName", searchableApplicant.getMiddleName().trim());
            query.setParameter("lastName", searchableApplicant.getLastName().trim());
           query.setParameter("dateOfBirth", searchableApplicant.getDob());   

Applicant Object properties:

 public class Applicant implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "applicant_id")
private Integer applicantId;
@Size(max = 45)
@Column(name = "first_name")
private String firstName;
@Size(max = 45)
@Column(name = "middle_name")
private String middleName;
@Size(max = 45)
@Column(name = "last_name")
private String lastName;
@Size(max = 45)
@Column(name = "maiden_name")
private String maidenName;
@Column(name = "dob")
@Temporal(TemporalType.DATE)
private Date dob;
unleashed
  • 331
  • 1
  • 5
  • 17

1 Answers1

0

The JSF date converters defaults to UTC timezone. When intepreting those dates using UTC timezone (as JSF by default does), you will get hours back in time and thus the previous day will be represented.

The solution is right here: JSF page reflects Date incorrectly - 1 Day shifted

Community
  • 1
  • 1
unleashed
  • 331
  • 1
  • 5
  • 17