1.hibernate的load和get方法都是先查找,查找不到再去数据库查,使用clear可以强制清除缓存,此外clear还会清除缓存的save、update、delete操作(Remove all objects from the org.hibernate.Session
cache, and cancel all pending saves, updates and deletes)。
2.Flush将缓存的操作立即执行掉(Flush all pending saves, updates and deletes to the database),包括update、save、delete操作,不使用Flush的话,hibernate会在事物提交的时候才执行持久化操作。
3.在使用clear之前,推荐执行下flush方法,否则可能会把缓存的更新操作给clear了,导致数据丢失的问题。