Announcement Announcement Module
Collapse
No announcement yet.
Transaction Problem. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transaction Problem.

    Hi,

    although I read this http://forum.springframework.org/sho...clob+hibernate thread, I still have problems configuring HibernateTransactionManager properly.

    From my applicationContext.xml:

    Code:
     <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
            <property name="dataSource">
                <ref local="myDataSource"/>
            </property>
            <property name="lobHandler">
                <ref bean="defaultLobHandler"/>
            </property>
            <property name="mappingResources">
                <list>
                    <value>contributor.hbm.xml</value>
                    <value>creator.hbm.xml</value>
                    <value>resource.hbm.xml</value>
                    <value>rights.hbm.xml</value>
                    <value>rightsholder.hbm.xml</value>
                </list>
            </property>
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect">net.sf.hibernate.dialect.MySQLDialect</prop>
                    <!--                <prop key="hibernate.query.substitutions">true=1 false=0</prop>-->
                    <prop key="hibernate.show_sql">true</prop>
                </props>
            </property>
        </bean>
    
      <bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">
            <property name="sessionFactory">
                <ref local="sessionFactory"/>
            </property>
        </bean>
    
        <bean id="galleryServiceTarget" class="com.vvdb.bus.gallery.logic.GalleryManager">
            <property name="galleryDao">
                <ref local="galleryDao"/>
            </property>
        </bean>
    
        <bean id="galleryService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
            <property name="transactionManager">
                <ref bean="transactionManager"/>
            </property>
            <property name="target">
                <ref bean="galleryServiceTarget"/>
            </property>
            <property name="transactionAttributes">
                <props>
                    <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
                    <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
                    <prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
                    <prop key="store*">PROPAGATION_REQUIRED</prop>
                </props>
            </property>
        </bean>
    
        <bean id="galleryDao" class="com.vvdb.db.gallery.HibernateGalleryDao">
            <property name="sessionFactory">
                <ref bean="sessionFactory"/>
            </property>
        </bean>
    When I call
    Code:
     galleryDao.storeGallery(gallery)
    from the galleryServiceTarget I get the infamous IllegalStateException: Active Spring transaction synchronization or jtaTransactionManager on LocalSessionFactoryBean plus active JTA transaction required.

    I must note that when I configured the TransactionProxyFactoryBean to target the galleryDao directly, this exception did not occur, and I was able to store the object in the database.

    In line with this my question is, what would be considered best practice in this case, have the service/manager objects manage the transactions or the DAO's. The petclinic example does not really help me in this respect, because I have the impression it is basically a 2-Tier example, without a service layer and (therefor?) all transaction management is performed on the DAO's...

    Your advice is greatly appreciated.

    Rgrds, Thomas
    Last edited by robyn; May 14th, 2006, 12:27 PM.

  • #2
    This http://forum.springframework.org/showthread.php?t=11135 post helped with the design issue, but I still have the exception to get around ...[/url]
    Last edited by robyn; May 14th, 2006, 12:50 PM.

    Comment


    • #3
      When I change the configuration in the followaing way it works.

      Code:
       <bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">
              <property name="sessionFactory">
                  <ref local="sessionFactory"/>
              </property>
          </bean>
      
          <bean id="galleryService" parent="galleryServiceBase">
              <property name="target">
                  <bean class="com.vvdb.bus.gallery.logic.GalleryService">
                      <property name="galleryDao">
                          <ref local="galleryDao"/>
                      </property>
                  </bean>
              </property>
          </bean>
      
          <bean id="galleryServiceBase" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
              <property name="transactionManager">
                  <ref bean="transactionManager"/>
              </property>
              <property name="target">
                  <ref bean="galleryService"/>
              </property>
              <property name="transactionAttributes">
                  <props>
                      <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
                      <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
                      <prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
                      <prop key="store*">PROPAGATION_REQUIRED</prop>
                  </props>
              </property>
          </bean>
      [/code]

      Comment

      Working...
      X