Nov 10, 2018

Examples of TemporalType in JPA

Example 1:

@Column(name
= "FOUNDED")
@Temporal(TemporalType.DATE)

private
Date created
Example 2:


query.setParameter("date",new java.util.Date(),TemporalType.DATE)
Since TemporalType.Date represents a pure date, the time part of the newly constructed java.util.Date instance is discarded. This is very useful in comparison against a specific date, when time should be ignored.

Example 3:

query="... where FUNCTION ('date', company.created) > :start  ";
// FUNCTION is one of EclipseLink's special operators

query.setParameter("start",
start, TemporalType.DATE);