Validating temporal fields

The java.util.Date and java.util.Calendar classes can be used to represent time in Java. If these classes are used for fields of an entity, the @Temporal annotation needs to be used. In addition, the @Future or @Past annotations are used to specify constraints on the relationship of the assigned date to the current time.

Getting ready

We will use the LicenseBean and LicenseBeanFacade classes from the ValidationApplication as discussed in the Validating persistent fields and properties recipe.

The @Temporal annotation designates a field as a time unit. JPA permits three basic mappings:

  • TemporalType.DATE
  • TemporalType.CALENDAR
  • TemporalType.TIMESTAMP

How to do it...

This annotation is used to annotate a Date or Calendar field as ...

Get EJB 3.1 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.