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

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -