hibernate第一个例子
?hibernate第一个例子
步骤
1? 新建web project或者 java project项目
2 添加架包

3 编写hibernate.cfg.xml
?
?
?
4? 编写实体类
? 单实体
Student.java
?
6 添加log4j.properties
Configuration cfg=new Configuration().configure(); SessionFactory sf=cfg.buildSessionFactory(); Session session= sf.openSession(); Transaction tx=session.beginTransaction(); Student s=new Student(); s.setName("测试1"); s.setPassword("22"); session.save(s); session.flush(); tx.commit(); session.close();?
9? 测试成功
?