清除缓存是为了向数据库增加数据时提高效率,否则就加到缓存里边了
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);
}
}