Hibernate clear方法:清空缓存

  • 内容
  • 评论
  • 相关

clear 方法用于清空缓存,即清除 Session 缓存中的所有持久化对象。当缓存中存放一定数量的持久化对象时,就会抛出缓存不足的异常。

语法:

clear()

示例

应用 clear 方法清除 Session 缓存中的所有持久化对象,关键代码如下:

Session session = sessionFactory.openSession();  //定义Session
UserForm uf = new UserForm();  //定义持久化类对象
uf = (UserForm)session.get("com.model.UserForm",1);
System.out.println("执行clear方法前,uf是否在缓存中:"+session.contains(uf));
session.clear();
System.out.println("执行clear方法后,uf是否在缓存中:"+session.contains(uf));

执行上面的代码,在控制台中将显示以下内容:
执行clear方法前,uf是否在缓存中:true
执行clear方法后,uf是否在缓存中:false

本文标题:Hibernate clear方法:清空缓存

本文地址:http://www.hosteonscn.com/6492.html

评论

0条评论

发表评论

邮箱地址不会被公开。 必填项已用*标注