Hibernate实战数据持久化之四Session的clear()、flush()、commit()、close()方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lycyl/article/details/80520186

flush()

        flush方法的主要作用就是清理缓存,强制数据库与hibernate缓存同步,以保证数据的一致性。

    通常,执行session.save,update,delete的时候,只是一个登记行为,只有在调用flush方法时,才会将hibernate缓存中的数据提交到数据库(将登记行为的sql提交到数据库,但是还是没有提交到数据库,没有保存数据)(Flush all pending saves, updates and deletes to the database)

commit()
          先调用flush方法,然后提交事务,意味着永久保存到数据库()

clear()
        强制 清除缓存, 此外 clear还会 清除缓存的save、update、delete操作( Remove all objects from the   org.hibernate.Session   cache, and cancel all pending saves, updates and deletes )


close()
         关闭session会话

猜你喜欢

转载自blog.csdn.net/lycyl/article/details/80520186
今日推荐