在以前的项目中,我们都是先设计数据库,将数据库中的表一一建好,在考虑实现。在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;
}
}