Can flushmode be used only once?

Inside my context app, I have 2 dao. if I assign my second tao below to use flushmode, I will get an invalid error ; The nested exception is org.xml.sax.SAXParseException: the value of the "org.springframework.orm.hibernate3.HibernateAccessor.FLUSH_COMMIT" attribute of the type identifier must be unique in the document . On the other hand, when I disabled flushmode for the 2nd tao, there is no error. can anyone explain this?

   <bean id="dao" class="info.jtrac.hibernate.HibernateJtracDao" init-method="createSchema">
        <property name="hibernateTemplate">
            <bean class="org.springframework.orm.hibernate3.HibernateTemplate">
                <property name="sessionFactory" ref="sessionFactory"/>
                <property name="flushMode">
                    <bean id="org.springframework.orm.hibernate3.HibernateAccessor.FLUSH_COMMIT"
                        class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean"/>                    
                </property>
            </bean>
        </property>        

    </bean>


    <bean id="secondsdao" class="com.company.secondSHibernateDao" >
        <property name="hibernateTemplate">
            <bean class="org.springframework.orm.hibernate3.HibernateTemplate">
                <property name="sessionFactory" ref="secondSsessionFactory"/>
               <property name="flushMode">
                    <bean id="org.springframework.orm.hibernate3.HibernateAccessor.FLUSH_COMMIT"
                        class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean"/>                    
                </property>

            </bean>
        </property>

    </bean>
+3
source share
2 answers

It is much simpler to configure flash mode by setting the appropriate constant as the String value:

<bean class="org.springframework.orm.hibernate3.HibernateTemplate">
  <property name="sessionFactory" ref="secondSsessionFactory"/>
  <property name="flushModeName" value="FLUSH_COMMIT" />
</bean>

, , HibernateAccessor, FieldRetrievingFactoryBean, , staticField:

<bean class="org.springframework.orm.hibernate3.HibernateTemplate">
  <property name="sessionFactory" ref="secondSsessionFactory"/>
  <property name="flushMode">
    <bean class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
      <property name="staticField" value="org.springframework.orm.hibernate3.HibernateAccessor.FLUSH_COMMIT"/>
    </bean>
  </property>
</bean>

Bean id - ; bean , , beans.

+1

id flushMode.

<property name="flushMode">
    <bean class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean"/>
</property>

. id .

,

+1

Source: https://habr.com/ru/post/1718679/


All Articles