在Hibernate中对于java.util.Date类型的映射为:
java类型 | Hibernate类型 | Mysql类型 |
java.util.Date、java.sql.Date | date | DATE |
java.util.Date、java.sql.Time | time | TIME |
java.util.Date、java.sql.Timestamp | timestamp | TIMESTAMP |
如果使用timestamp作为Date类型映射时,具体代码如下:
Java代码
public class User {
private String userPK;
private String userID;
private String password;
private String nickname;
private boolean state;
private boolean role;
private Date registerDate;
private int points;
public String getUserPK() {
return userPK;
}
private void setUserPK(String userPK) {
this.userPK = userPK;
}
public String getUserID() {
return userID;
}
public void setUserID(String userID) {
this.userID = userID;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public Date getRegisterDate() {
return registerDate;
}
public void setRegisterDate(Date registerDate) {
this.registerDate = registerDate;
}
public int getPoints() {
return points;
}
public void setPoints(int points) {
this.points = points;
}
public void setState(boolean state) {
this.state = state;
}
public boolean getState(){
return this.state;
}
public void setRole(boolean role) {
this.role = role;
}
public boolean getRole(){
return this.role;
}
}