title: Setting FlushMode.COMMIT in Spring
body: <p>I would like set my Hibernate/JPA FlushMode to COMMIT, but in configuration file (applicationContenxt.xml is one of my files), i have a entityManager in my DAO, but i don't know how to set this in configuration file.</p>
  
  <p>So, this is my applicationContext.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xsi:schemaLocation="http://www.springframework.org/schema/beans 
          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context-3.0.xsd
          http://www.springframework.org/schema/tx
          http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"&gt;
  
      &lt;!-- Seta anotaçoes para serem usadas pelo Spring --&gt;
      &lt;context:annotation-config /&gt;
  
      &lt;!-- Define o pacote onde o Spring vai procurar por beans anotados --&gt;
      &lt;context:component-scan
          base-package="br.com.sender" /&gt;
  
      &lt;!-- define que as transaçoes irao ser anotadas --&gt;
      &lt;tx:annotation-driven proxy-target-class="true" /&gt; 
  
      &lt;!-- Configuracao do Banco de Dados --&gt;
      &lt;bean id="dataSource"
          class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
          &lt;property name="driverClassName" value="org.postgresql.Driver" /&gt;
          &lt;property name="url" value="jdbc:postgresql://localhost/sender" /&gt;
          &lt;property name="username" value="postgres" /&gt;
          &lt;property name="password" value="pgadmin" /&gt;
      &lt;/bean&gt;
  
      &lt;!-- Configuracao do Hibernate --&gt;
      &lt;bean id="entityManagerFactory"
          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
          &lt;property name="persistenceUnitName" value="senderPU" /&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="jpaVendorAdapter"&gt;
              &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
                  &lt;property name="databasePlatform" value="org.hibernate.dialect.PostgreSQLDialect" /&gt;
                  &lt;property name="showSql" value="true" /&gt;
              &lt;/bean&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;!-- Configuracao do gerente de transacoes do Spring --&gt;
      &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
          &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>EDIT 1:</p>
  
  <p>I tried the following in applicationContext.xml</p>
  
  <pre><code>&lt;bean id="entityManagerFactory"
          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
            &lt;property name="jpaDialect"&gt;
          &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"&gt;
              &lt;property name="flushMode" value="COMMIT"/&gt;
          &lt;/bean&gt;
          &lt;/property&gt;
  </code></pre>
  
  <p>Tomcat error:</p>
  
  <pre><code>aused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'flushMode' of bean class [org.springframework.orm.jpa.vendor.HibernateJpaDialect]: Bean property 'flushMode' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
      at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1052)
      at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:921)
      at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:76)
      at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1358)
      ... 53 more
  </code></pre>
  
  <p><strong>SOLUTION:</strong></p>
  
  <p>After a lot of research, i found a solution. I setted the FlushMode in @PersistenceContext in my BasicDAO class. Look:</p>
  
  <pre><code>@PersistenceContext(type = javax.persistence.PersistenceContextType.EXTENDED, 
          properties = @PersistenceProperty(name="org.hibernate.flushMode", value="COMMIT"))
      protected EntityManager entityManager;
  </code></pre>
  
  <p>This works fine. I removed all @Transactional annotation from my "find" functions, because with @Transactional the "COMMIT" are fired and flush too.</p>