I want to insert data with automatic insertion of created_at date time and respective updated_at date time.
I have a pojo as:
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@Basic(optional = false)
@Column(name = "name")
private String name;
@Basic(optional = false)
@CreationTimestamp
@Column(name = "created_at")
@Temporal(TemporalType.TIMESTAMP)
private Date createdAt;
@UpdateTimestamp
@Column(name = "updated_at")
@Temporal(TemporalType.TIMESTAMP)
private Date updatedAt;
And in my database, I have used DATETIME as a type for created_at and updated_at. But I am not being able to insert data rather it gives an error message not-null property references a null or transient value: com.project.test.entity.Stamp.createdAt.
I want to know the proper way to define my database schema for created_at and updated_at DateTime field to make it generate automatically.