第一步:导入hibernate的jar包 到WEB-INF的lib下
第二步:在src目录下写一个hibernate.cfg.xml配置文件
/p>
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
true
jdbc:oracle:thin:@localhost:1521:ORCL
bsp
bsp
oracle.jdbc.OracleDriver
1
thread
org.hibernate.dialect.Oracle9Dialect
update
第三步:在src目录下建一个com.entity包,里面建一个Person类
package com.bsp.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class Person {
private String id;
private String name;
@Id
@Column(length=10)
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@Column(length=10)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
第四步:建一个测试类
package com.bsp.test;
import org.hibernate.Session;
import com.HibernateSessionFactory;
import junit.framework.TestCase;
public class TestBsp extends TestCase{
public void testSave() throws Exception {
Session session = HibernateSessionFactory.getSession();
session.close();
}
}
运行就可以自动在数据库里生成表了