java - Hibernate with Annotations and MySQL: Creation Date -
i try save date of creation of entity. have found that approach. tried implement date doesn't reach db-table.
import java.io.serializable; import java.util.date; import javax.persistence.entity; import javax.persistence.id; import javax.persistence.prepersist; @entity public class project implements serializable { private static final long serialversionuid = 7620757776698607619l; @id int id; string title; date created; public int getid() { return id; } public void setid(int id) { this.id = id; } public void settitle(string title) { this.title = title; } public string gettitle() { return title; } @prepersist protected void oncreate() { created = new date(); } public date getcreated() { return created; } }
only title being saved. field data empty :-(
where mistake? thank helping me.
update
i tried add annotation of pascal didn't help. possible should use sql.date istead of utils.date. try can't find how today's date...
i wonder if lack of setter created
date not problem. aside, define temporal
annotation on created
date save date and time. this:
@entity public class project implements serializable { @id private int id; private string title; @temporal(temporaltype.timestamp) private date created; ... public date getcreated() { return created; } public void setcreated(date created) { this.created = created; } @prepersist protected void oncreate() { created = new date(); } }
Comments
Post a Comment