在Hibernate手册中,您可以看到此示例
Session session = sessionFactory.openSession();Transaction tx = session.beginTransaction();for (int i = 0; i < 100000; i++) { Customer customer = new Customer(...); session.save(customer); if (i % 20 == 0) { // 20, same as the JDBC batch size // flush a batch of inserts and release memory: session.flush(); session.clear(); }}tx.commit();session.close();如果不调用flush方法,则一级缓存将抛出OutOfMemoryException
您也可以看一下有关冲洗的帖子



