In this section we look at how date and time is handled. If we want to persist a field of type java.util.Date
we need to use the @Temporal
annotation. This is described in the next subsection. The subsection "Queries with Date Parameters" shows how we handle a query with a java.util.Date
or java.util.Calendar
parameter. Finally the subsection "Datetime Functions" describes the date and time functions provided by JPQL.
Suppose we add a new field, dateOpened
, of type java.util.Date
in the Account entity. The dateOpened
variable indicates the date on which the account was opened. We must use the @Temporal(TemporalType.DATE)
annotation, which can be either field-based or property-based, to indicate that the field will be mapped onto the java.sql.Date
database type. This is shown in the following code fragment:
@Entity public class Account implements Serializable { private int id; private double balance; private String accountType; private Customer customer...