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

From Eclipsepedia

Jump to: navigation, search
m (New page: {{EclipseLink_UserGuide|info=y|toc=n}} =@Temporal= {{EclipseLink_JPA |previous=Enumerated |next= ...)
 
m
Line 1: Line 1:
 
{{EclipseLink_UserGuide|info=y|toc=n}}
 
{{EclipseLink_UserGuide|info=y|toc=n}}
 
=@Temporal=
 
=@Temporal=
 +
Use the <tt>@Temporal</tt> annotation to specify the database type that EclipseLink persistence provider should persist for persistent fields or properties of type <tt>java.util.Date</tt> and <tt>java.util.Calendar</tt> only.
  
 +
You can use this annotation with the [[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Mapping/Basic_Mappings|<tt>@Basic</tt> annotation]].
 +
 +
{{EclipseLink_AttributeTable
 +
|caption=The <tt>@Temporal</tt> annotation has the following attributes:
 +
|content=<tr>
 +
<td>'''<tt>value</tt>'''</td>
 +
<td>Set this attribute to the <tt>TemporalType</tt> that corresponds to database type you want EclipseLink persistence provider to use:
 +
* <tt>DATE</tt> – equivalent of <tt>java.sql.Date</tt>
 +
* <tt>TIME</tt> – equivalent of <tt>java.time.Date</tt>
 +
* <tt>TIMESTAMP</tt> – equivalent of <tt>java.sql.Timestamp</tt></td>
 +
<td></td>
 +
<td>Yes</td>
 +
</tr>
 +
}}
 +
 +
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.
 +
 +
 +
<span id="Example 18-14"></span>
 +
''''' Usage of the @Temporal Annotation'''''
 +
<source lang="java">
 +
@Entity
 +
public class Employee implements Serializable{
 +
    ...
 +
    @Temporal(DATE)
 +
    protected java.util.Date startDate;
 +
    ...
 +
}
 +
</source>
 +
 +
{{EclipseLink_Spec
 +
|section=Section 9.1.20 "Temporal Annotation"
 +
}}
  
  
Line 8: Line 42:
 
|next=    [[EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Basic Mappings/Lob|Lob]]
 
|next=    [[EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Basic Mappings/Lob|Lob]]
 
|up=      [[EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Basic Mappings|Basic Mappings]]
 
|up=      [[EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Basic Mappings|Basic Mappings]]
 +
|version= 2.1.0
 
}}
 
}}

Revision as of 09:51, 21 June 2010


link="http://wiki.eclipse.org/EclipseLink"
EclipseLink
Website
Download
Community
Mailing ListForumsIRC
Bugzilla
Open
Help Wanted
Bug 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.

The @Temporal annotation has the following 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

This 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.


Usage of the @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.1.0
Other versions...