Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Basic Mappings/Temporal"

(@Temporal)
(Example: @Temporal Annotation)
Line 32: Line 32:
 
======'' Example: @Temporal Annotation''======
 
======'' Example: @Temporal Annotation''======
 
<source lang="java">
 
<source lang="java">
@Entity
+
@Entity
public class Employee implements Serializable{
+
public class Employee implements Serializable {
    ...
+
    ...
    @Temporal(DATE)
+
    @Temporal(DATE)
    protected java.util.Date startDate;
+
    protected java.util.Date startDate;
    ...
+
    ...
}
+
}
 +
</source>
 +
 
 +
======''Example: Using <code><nowiki><temporal></nowiki></code> XML''======
 +
<source lang="xml">
 +
<entity class="Employee">
 +
    <attributes>
 +
        ...
 +
        <basic name="startDate">
 +
            <temporal>DATE</temporal>
 +
        </basic>
 +
        ...
 +
    </attributes>
 +
</entity>
 
</source>
 
</source>
  
Line 45: Line 58:
 
}}
 
}}
  
 +
====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 <code>TIMESTAMPTZ</code> and <code>TIMESTAMPLTZ</code> types in Oracle.
 +
Seee, [[EclipseLink/UserGuide/JPA/Oracle|Oracle]].
  
 
{{EclipseLink_JPA
 
{{EclipseLink_JPA

Revision as of 14:09, 27 October 2011

EclipseLink JPA

Eclipselink-logo.gif
EclipseLink
Website
Download
Community
Mailing ListForumsIRCmattermost
Issues
OpenHelp WantedBug Day
Contribute
Browse Source

Elug api package icon.png Key API


@Temporal

Use the @Temporal annotation 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
Yes


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
@Entity
public class Employee implements Serializable {
    ...
    @Temporal(DATE)
    protected java.util.Date startDate;
    ...
}
Example: Using <temporal> XML
<entity class="Employee">
    <attributes>
        ...
        <basic name="startDate">
            <temporal>DATE</temporal>
        </basic>
        ...
    </attributes>
</entity>
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. Seee, Oracle.

Eclipselink-logo.gif
Version: 2.2.0 DRAFT
Other versions...

Back to the top