转变Hibernate的使用方式
private String id;
private String name;
private String password;
private Date createTime;
private Date expireTime;
//一系列setter.getter方法
}
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
< hibernate-configuration >
< session-factory >
< property name ="hibernate.connection.url" >jdbc:oracle:thin:@localhost:1521:test </ property >
< property name ="hibernate.connection.driver_class" >oracle.jdbc.driver.OracleDriver </ property >
< property name ="hibernate.connection.username" >SCOTT </ property >
< property name ="hibernate.connection.password" > yf123 </ property >
< property name ="hibernate.dialect" >org.hibernate.dialect.Oracle9Dialect </ property >
< property name ="hibernate.show_sql" >true </ property >
< mapping resource ="com/yf/hibernate/Student.hbm.xml" />
</ session-factory >
</ hibernate-configuration >
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
< hibernate-mapping >
< class name ="com.yf.hibernate.Student" table ="hibernate_student" >
< id name ="id" length ="6" >
< generator class ="uuid" />
</ id >
< property name ="name" length ="10" />
< property name ="password" length ="8" />
< property name ="createTime" />
< property name ="expireTime" />
</ class >
</ hibernate-mapping >
import org.hibernate.tool.hbm2ddl.SchemaExport;
public class ExportDB {
public static void main(String[] args) {
// 读取hibernate.cfg.xml文件
Configuration cfg = new Configuration().configure();
SchemaExport export = new SchemaExport(cfg);
export.create( true, true); //第一个为True就是把DDL语句输出到控制台,第二个为True就是根据持久类和映射文件执行删除数据库架构操作
}
}