读书人

hibernate第一个例证

发布时间: 2012-11-15 15:16:14 作者: rapoo

hibernate第一个例子



?hibernate第一个例子

步骤

1? 新建web project或者 java project项目

2 添加架包

hibernate第一个例证

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? 测试成功

?

读书人网 >软件架构设计

热点推荐