Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: for the plan.

Jump to: navigation, search

EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Basic Mappings/Temporal

EclipseLink JPA

Mailing ListForumsIRCmattermost
OpenHelp WantedBug Day
Browse Source

Elug api package icon.png Key API


Use the @Temporal annotation or <temporal> XML to specify the database type that EclipseLink persistence provider should persist for persistent fields or properties of type java.util.Date and java.util.Calendar only.

You can use this annotation with the @Basic annotation.

@Temporal Attributes
Attribute Description Default Required?
value Set this attribute to the TemporalType that corresponds to database type you want EclipseLink persistence provider to use:
  • DATE – equivalent of java.sql.Date
  • TIME – equivalent of java.sql.Time
  • TIMESTAMP – equivalent of java.sql.Timestamp

The following example shows how to use this annotation to specify that EclipseLink persistence provider should persist java.util.Date field startDate as a DATE (java.sql.Date) database type.

Example: @Temporal Annotation
public class Employee implements Serializable {
    protected java.util.Date startDate;
Example: Using <temporal> XML
<entity class="Employee">
        <basic name="startDate">
Elug javaspec icon.gif

For more information, see Section 11.1.47 "Temporal Annotation" in the JPA Specification.

Timezones and Calendars

In Java a Calendar also stores a timezone and day light saving offset in addition to the date and time values. Normally this timezone is lost when storing the Calendar to the database. Some databases have support for storing timezones and offsets, so it is possible to store these to the database as well.

EclipseLink supports storing timezones in an Oracle database through the TIMESTAMPTZ and TIMESTAMPLTZ types in Oracle. To store timezones, ensure the column is of type TIMESTAMPTZ, Calendar is used as the type in Java, and the Oracle9Platform or higher is used. You can also use a TypeConverter and set the dataType to oracle.sql.TIMESTAMPTZ or oracle.sql.TIMESTAMPLTZ.

Version: 2.2.0 DRAFT
Other versions...

Back to the top