java entity date code example

Example: java.sql.Date jpa

@Entity
public class MyEntity {
 
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
     
    @Temporal(TemporalType.TIMESTAMP)
    private Date utilDate;
     
    @Temporal(TemporalType.DATE)
    private Calendar utilCalendar;
     
    ...
     
    public Date getUtilDate() {
        return utilDate;
    }
 
    public void setUtilDate(Date utilDate) {
        this.utilDate = utilDate;
    }
 
    public Calendar getUtilCalendar() {
        return utilCalendar;
    }
 
    public void setUtilCalendar(Calendar utilCalendar) {
        this.utilCalendar = utilCalendar;
    }
}

Tags:

Java Example