Reputation: 1
I 'm using Hibernate framework as way of mapping from Javabean to Database for my project which applied by Spring framework.But, I don' know how to insert Date type in Hibernate
My code :
import java.util.Date; ...................................... @Column(name = "date") private Date date; @SuppressWarnings("deprecation") public void setDate(String date) { Date date1 = new Date(date); this.date = date1; }
My register.jsp
<tr>
<td><form:label path="date">Date</form:label></td>
<td><form:input path="date" /></td>
</tr>
After submitting.date fileds in databse is null. It's value can not be mapped into Account table in database
Note: Account means :
@Entity
@Table(name="Account")
public class User {
Please help me.Thanks
Upvotes: 0
Views: 4627
Reputation: 11
I also has this problem.When I insert date type object into DB,it turns out null value.
My date type in DB is Datetime type.In my case,it is format problem.
Then I try to do so,then solved it,after following formatting.
Date date=new Date();
SimpleDateFormat spl=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String d=spl.format(date);
date=spl.parse(d);
You can try it.
Upvotes: 1
Reputation: 6739
in your User class use the following to map the column as date type
@Column(name = "date")
@Temporal(TemporalType.DATE)
private Date date;
Upvotes: 0