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"

m
m
Line 11: Line 11:
  
 
{{EclipseLink_AttributeTable
 
{{EclipseLink_AttributeTable
|caption=The <tt>@Temporal</tt> annotation has the following attributes:
+
|caption=@Temporal Attributes:
 
|content=<tr>
 
|content=<tr>
 
  <td>'''<tt>value</tt>'''</td>
 
  <td>'''<tt>value</tt>'''</td>
Line 23: Line 23:
 
}}
 
}}
  
This example shows how to use this annotation to specify that EclipseLink persistence provider should persist <tt>java.util.Date</tt> field <tt>startDate</tt> as a <tt>DATE</tt> (<tt>java.sql.Date</tt>) database type.
 
  
 +
The following example shows how to use this annotation to specify that EclipseLink persistence provider should persist <tt>java.util.Date</tt> field <tt>startDate</tt> as a <tt>DATE</tt> (<tt>java.sql.Date</tt>) database type.
  
<span id="Example 18-14"></span>
+
======'' Example: @Temporal Annotation''======
''''' Usage of the @Temporal Annotation'''''
+
 
<source lang="java">
 
<source lang="java">
 
  @Entity
 
  @Entity

Revision as of 13:40, 29 March 2011

EclipseLink JPA

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


@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.time.Date
  • 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;
     ...
 }
Elug javaspec icon.gif

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


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

Back to the top