博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Hibernate中持久化上下文的flush操作之一MANUAL
阅读量:4179 次
发布时间:2019-05-26

本文共 683 字,大约阅读时间需要 2 分钟。

对于Hibernate中的两种持久化上下文,JPA的EntityManager和Hibernate的Session,两者都提供了flush()方法。任何时候在应用中调用该方法,则触发持久化上下文与数据库的同步。

除此之外,还可以为Hibernate的Session设置flush模式为MANUAL(JPA的EntityManager不支持),即Hibernate的Session只支持手工执行flush操作,示例如下:

Person person = new Person("John Doe");entityManager.persist(person);Session session = entityManager.unwrap( Session.class);session.setFlushMode( FlushMode.MANUAL);entityManager    .createQuery("select count(id) from Person")    .getSingleResult();session    .createSQLQuery("select count(*) from Person")    .uniqueResult();//flush executedsession.flush();
在上述示例中,执行native SQL查询并不能触发Hibernate的Session执行flush操作,只有调用Hibernate的Session的flush()方法时才触发Hibernate的Session执行flush操作。

转载地址:http://ailai.baihongyu.com/

你可能感兴趣的文章
安装composer时出现 failed to open stream: HTTP request failed!的错误
查看>>
禁用HBuilderX自动更新
查看>>
C++字符串函数
查看>>
mknod详解
查看>>
linux中的run-level何解?
查看>>
Linux内核编译详解(转自linuxSir)
查看>>
实模式,保护模式与V86模式
查看>>
628. Maximum Product of Three Numbers(排序)
查看>>
Linux内核-------同步机制(一)
查看>>
485. Max Consecutive Ones(数组)
查看>>
287. Find the Duplicate Number(数组)
查看>>
Linux内核-------同步机制(二)
查看>>
面试题31-------连续子数组的最大和(数组)
查看>>
epoll 实现Chat
查看>>
21. Merge Two Sorted Lists(链表)
查看>>
2. Add Two Numbers(链表)
查看>>
637. Average of Levels in Binary Tree(Tree)
查看>>
226. Invert Binary Tree(Tree)
查看>>
328. Odd Even Linked List(链表)
查看>>
617. Merge Two Binary Trees(Tree)
查看>>