Problem in mapping Date with Hibernate


#1

Hi Sir,

I am trying to insert the date in oracle using java.util.Date object , but when i am trying to create a date object it is showing that the constructor for Date is deprecated.
how to solve the issue and suggest a possible solution to insert the date in database.


#2

That’s not a Hibernate or data access layer issue.

That Date constructor has been deprecated by Java, and you can construct in many ways, even from a String template:

DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date dateObject = sdf.parse("2018-02-03");

The mapping should be like this:

@Temporal(TemporalType.DATE)
private Date birthday;

#3

Thank You Vlad Sir for the solution…


#4

You are very welcome.