How do I set flush mode to “COMMIT” in my configuration files?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 07:14:16

Check this link

You may need to extend

org.springframework.orm.jpa.vendor.HibernateJpaDialect 

I hope this helps!

Try the following in your web.xml

<filter>
    <filter-name>openSessionInViewFilter</filter-name>
    <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
    <init-param>
        <param-name>flushMode</param-name>
        <param-value>COMMIT</param-value>
    </init-param>
</filter>

Reference.

As another option, you can configure the Hibernate EntityManager directly to use a particular flush mode by default using the org.hibernate.flushMode configuration setting.

I am not sure if this type of setting is available in spring. (I haven't seen one) But, as an alternative hibernate provides generic CRUD methods that you can use for all your classes if you pass them in as generics. Just put the call to the flush method in the Update/Create methods and use these exclusively to create/update all your classes.

Here is an example:

http://www.ibm.com/developerworks/java/library/j-genericdao/index.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!