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