Reputation: 141
I'm creating web application. I'm using Spring and hibernate. When doing the below,
userprofile.setFirstName(firstname);
userprofile.setLastName(lastname);
userprofile.setDob(bday);
userprofile.setPhoneNumber(telephone);
userprofile.setEmailId(email);
userprofile.setPassword(password);
// userprofile.setCreatedDate(sysdate);
session.save(userprofile);
t.commit();
Hibernate is generating the below insert query
Hibernate: insert into USER_PROFILE (CREATED_DATE, DATE_OF_BIRTH, EMAIL_ID, FIRST_NAME, LAST_NAME, PASSWORD, PHONE_NUMBER, PROFILE_ID) values (?, ?, ?, ?, ?, ?, ?, ?)
which is inserting null value in my created_date field. I've made that created_date field's default value as sysdate. Please help me to sort out this.
Upvotes: 1
Views: 244
Reputation: 141
I got it resolved..In pojo class, the following insertable=false should be added. This will avoid insertion of null and default value set in table will be inserted instead.
@Column(name = "CREATED_DATE", insertable=false)
private Date createdDate;
Upvotes: 1