在以前的項目中,我們都是先設計數據庫,將數據庫中的表一一建好,在考慮實現。在Hibernate中,我們不用在手動去建表,而是通過映射來操作數據庫。怎樣操作數據庫呢?Hibernate3中為我們提供了hbm2ddl這樣的工具,下面讓我們看一個具體事例:
package com.bjpowernode.hibernate;
import java.util.Date;
/**
* 實體類User
* @author lyj
*
*/
public class User {
private String id;
private String name;
private String password;
private Date createTime;
private Date expireTime;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getExpireTime() {
return expireTime;
}
public void setExpireTime(Date expireTime) {
this.expireTime = expireTime;
}
}