views:

337

answers:

2

Inside my applicationContext, I have 2 dao . if i assign my 2nd dao below to use flushmode, i will get error invalid; nested exception is org.xml.sax.SAXParseException: Attribute value "org.springframework.orm.hibernate3.HibernateAccessor.FLUSH_COMMIT" of type ID must be unique within the document. On the other hand, when i excluded flushmode for 2nd dao, no error. can anyone explain on 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>
+1  A: 

Hi,

Just remove id attribute from both flushMode property.

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

Advice: you can not use the same id attribute in more than one element.

regards,

Arthur Ronald F D Garcia
+1  A: 

It's much easier to configure flush mode by supplying appropriate constant as String value:

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

However, if you'd rather retrieve that value from a constant defined in HibernateAccessor, you need to configure FieldRetrievingFactoryBean properly by specifying the name of field you're retrieving as staticField property:

<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 is something entirely different; it's used to uniquely identify the bean in application context and, as Arthur pointed out, can be omitted for inner beans.

ChssPly76
i used the 2nd technique u outlined and it work. may i know do i need to create "staticField" in any java file?
cometta
"staticField" tells `FieldRetrievingFactoryBean` to get the value of whatever attribute was specified - in this case `HibernateAccessor`'s `FLUSH_COMMIT`. So no, you don't need to create anything.
ChssPly76