1.和它的增改查兄弟不同,多了个until包定义了HibernateUntil类,让我们来一起看看吧

 public class HibernateUntil {
private static Configuration cfg=new Configuration().configure();
private static SessionFactory factory=cfg.buildSessionFactory(); //1.方法返回session 静态成员变量不能直接使用非静态成员
//Session依赖于Session工厂,工厂依赖于Configure
public static Session getSession(){
return factory.openSession(); }
//2.关闭session
public static void closeSession(){
getSession().close();
}

这里也考察了一个知识点静态变量与非静态变量    要想学好就得把基础打好!

2.接下来我们来写一下测试类

 @Test
public void testhibernate() {
deleteStudent();//删除学生
}
  private void deleteStudent() {
Session session= HibernateUntil.getSession();
Student student=new Student();
student.setSid();
//开启事务
Transaction tx=session.beginTransaction();
session.delete(student);
tx.commit();
HibernateUntil.closeSession();
System.out.println("success ok");
}

恩,Hibernate系列增删改查就此结束,感谢同行们的阅览哈!

最新文章

  1. 服务器IIS同时支持ASP和PHP
  2. HDU 5102 The K-th Distance(模拟)
  3. WebStorm 10.0.4注册码
  4. hibernate(1)
  5. Rxlifecycle(二):源码解析
  6. JAVA与指针
  7. 用FileInputStream读文件,字节数组接收,不知道文件的大小时怎么办
  8. .Net 执行 Oracle SQL语句时, 中文变问号
  9. hdu1003 Max Sum(经典dp )
  10. RedHat Enterprise Linux 6.3 安装Oracle Database 11g
  11. visual studio code, asp.net5, mvc6资料汇总
  12. 重新绑定ItemsSource先设置ItemsSource = null;的原因
  13. .net操作IIS,新建网站,新建应用程序池,设置应用程序池版本,设置网站和应用程序池的关联
  14. Redis集群架构
  15. 【Linux基础】mount报错:mount.nfs: Remote I/O error
  16. 【论文速读】Chuhui Xue_ECCV2018_Accurate Scene Text Detection through Border Semantics Awareness and Bootstrapping
  17. mac常用操作
  18. SDL中 so库的使用
  19. Python流程控制if判断以及whlie循环
  20. js点击回到顶部

热门文章

  1. J2SE-鸡汤
  2. SAP 740GUI客户端快捷方式取消密码登陆
  3. 对于vue的一些理解
  4. left jion on和where条件的区别
  5. 【NOIP 2015】斗地主
  6. 数据结构42:n个结点构造多少种树
  7. vue.js组件之j间的通讯四,通过单一事件来管理组件通讯
  8. [PowerShell] check PowerShell Version
  9. Unity 动画系统目录 之 Animation
  10. lintcode - 统计比给定整数小的数的个数(两种方法)