Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is it necessary to annotate mapped Date fields @Temporal in javax.persistence?

The format goes like this:

@Temporal(TemporalType.DATE)
@Column(name="CREATED_DATE")
private Date createdDate;

My question is: Why is it necessary to annotate mapped java.util.Date fields as @Temporal in javax.persistence? If the local variable is obviously declared as a Date and the column data type in the DB is also one of the date(time) or timestamp types, shouldn't it be easy to infer that we're dealing with a temporal bit of data without redundantly specifying it in multiple places?

like image 604
amphibient Avatar asked Dec 05 '22 23:12

amphibient


1 Answers

From e.g. java.util.Date it's not obvious if one wants to map to DATE or TIMESTAMP database type. Only exception is java.sql.Date/Time.

like image 136
wgitscht Avatar answered Mar 02 '23 00:03

wgitscht