Organizational Research By

Surprising Reserch Topic

how do i set flush mode to commit in my configuration files

how do i set flush mode to commit in my configuration files  using -'spring,hibernate,jpa,transactions,flush'

I'm using Spring 3.1.1.RELEASE, Hibernate 4.1.0.Final, and JPA 2.0.  Is there a way I can configure Spring transactions to commit after the transactions are executed without Java code?  In other words, I would like to set flush mode to commit in either the application context file, hibernate configuration file, or persistence.xml file.  My Spring transaction service class looks like

@Transactional(rollbackFor = Exception.class)
public class ContractServiceImpl implements ContractService

    private ContractDAO m_contractDao;

    public void addContract(Contract contract)


and my application context is set up like so …

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
    <property name="url" value="jdbc:hsqldb:mem:myproject" />
    <property name="username" value="sa" />
    <property name="password" value="" />

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
    <property name="persistenceXmlLocation" value="classpath*:META-INF/test-persistence.xml"/>
    <property name="persistenceUnitName" value="testingDatabase"/>
    <property name="dataSource" ref="dataSource"/>

<bean id="sharedEntityManager" class="">
   <property name="entityManagerFactory" ref="entityManagerFactory"/>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>

<tx:annotation-driven />

My persistence.xml file is

<persistence version="2.0"
   xmlns="" xmlns:xsi=""
        <persistence-unit name="testingDatabase" transaction-type="RESOURCE_LOCAL">
                        <property name="hibernate.ejb.cfgfile" value="/hsql_hibernate.cfg.xml" />
        <property name="org.hibernate.FlushMode" value="commit" />

and my hibernate config file is

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"

        <property name="hibernate.connection.pool_size">1</property>
        <property name="show_sql">true</property>
        <property name="dialect">org.hibernate.dialect.HSQLDialect</property>
        <property name="">create-drop</property>

        <mapping class="org.mainco.subco.sbadmin.domain.Product" />
        <mapping class="org.mainco.subco.sbadmin.domain.Contract" />
        <mapping class="org.mainco.subco.organization.domain.Country" />
        <mapping class="org.mainco.subco.organization.domain.State" />
        <mapping class="org.mainco.subco.organization.domain.Address" />
        <mapping class="org.mainco.subco.organization.domain.OrganizationType" />
        <mapping class="org.mainco.subco.organization.domain.Organization" />



asked Sep 14, 2015 by vimaldas2005
0 votes

Related Hot Questions

3 Answers

0 votes

Try the following in your web.xml



answered Sep 14, 2015 by JaninaNumber
0 votes

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.

answered Sep 14, 2015 by MuhMccombs
0 votes

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:

answered Sep 14, 2015 by MichaelEveri