清除缓存

清除缓存是为了向数据库增加数据时提高效率,否则就加到缓存里边了

package com.haha.test;

import java.util.List;

import org.hibernate.Hibernate;
import org.hibernate.Session;

import com.haha.dao.HibernateSessionFactory;
import com.haha.info.Books;

public class Test1 {


public static void main(String[] args) {
Session ss=HibernateSessionFactory.getSession();
List<Books> list=ss.createQuery("from Books").list();
System.out.println("-----------");
Books bk1=(Books) ss.get(Books.class, 5000);
ss.clear();//清除所有缓存
//ss.evict(bk1);//清除指定对象

Books bk2=(Books) ss.get(Books.class, 5000);

System.out.println(bk1==bk2);
}

}

posted on 2015-11-13 15:55  kebizhanmushi  阅读(160)  评论(0编辑  收藏  举报

导航