1.hibernate3.3.2日志配置,默认采用slf处理日志,slf只是接口,在slf发行包里有对其它日志框架的支持(适配器),加入包slf4j-log4j12-1.5.8然后再加入对应的log4j包,最后在项目中加入log4j.properties就可以用log4j了.
2.启动log4j.properties中的log4j.logger.org.hibernate.tool.hbm2ddl=debug就可以在运行时看到建表语句.
3.hibernate.cfg.xml中的,
<property name="show_sql">true</property> 显示sql语名
<property name="format_sql">true</property> 格式化sql语句
<property name="hbm2ddl.auto">create</property> SessionFactory重新创建时创建表
4.junit测试
public class StudentTest {
private static SessionFactory sf = null;
@BeforeClass
public static void beforeClass(){
sf = new AnnotationConfiguration().configure().buildSessionFactory();
}
@AfterClass
public static void afterClass(){
sf.close();
}
@Test
public void test1(){
Student s = new Student();
s.setId(5);
s.setAge(12);
s.setName("小明");
Session session = sf.openSession();
session.beginTransaction();
session.save(s);
session.getTransaction().commit();
session.close();
}
}