Announcement Announcement Module
Collapse
No announcement yet.
BeanNameAutoProxyCreator doesn't wrap all methods? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • BeanNameAutoProxyCreator doesn't wrap all methods?

    I'm having some trouble with the BeanNameAutoProxyCreator example. I have a service layer defined for the use of Sping managed transactions. All of the service beans are defined, however, some methods are not being committed. After looking at the JBOSS server log, I only see service methods with the naming convention getXXX and deleteXXX being wrapped in a transaction. Does the BeanNameAutoProxyCreator only wraps those methods complaint with the JavaBean naming convention? If so, is there another implementation that will wrap all public methods?

  • #2
    Alright so my log was just incorrect. I cleared out the server tmp directories and restarted services. I can now see all service methods correctly wrapped in a JTA transaction.

    However, the data is still not being committed to the database after the JTA Interceptor reports having called commit. I have been able to fix this by adding a call to flush() on the underlying Hibernate session. However, I can't do this for every method that makes calls to Hibernate.

    Is there another solution?

    Comment


    • #3
      Here is the relevant configuration. It's pretty simple though it seems to be a little out-of-the-box. Hibernate and Spring JTA aren't exactly aware of each other. I'm expecting Hibernate to pick up the Spring JTA by using the common name 'UserTransaction.'

      Here is the app context for spring:

      Code:
      <?xml version="1.0" encoding="UTF-8" ?>
      <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
      
      <!-- This is the EJB-centric application context that will be loaded by -->
      <!-- the Spring bean factory locator                                    -->
      <beans>
      	<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
      		<property name="userTransactionName">
      			<value>UserTransaction</value>
      		</property>
      	</bean>		
      	
      	<bean id="userAdminService" 
      			singleton="true"
      class="com.xxx.service.OdinUserAdminService"/>
      
      ...other beans...	
      	
      	<!-- Transaction Interceptor set up to do PROPAGATION_REQUIRED on all methods -->
      	<bean id="matchAllWithPropReq" 
      			class="org.springframework.transaction.interceptor.MatchAlwaysTransactionAttributeSource">
      		<property name="transactionAttribute">
      			<value>PROPAGATION_NESTED</value>
      		</property>
      	</bean>
      	
      	<bean id="matchAllTxInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
      		<property name="transactionManager">
      			<ref bean="transactionManager"/>
      		</property>
      		<property name="transactionAttributeSource">
      			<ref bean="matchAllWithPropReq"/>
      		</property>
      	</bean>
      
      	<!-- One BeanNameAutoProxyCreator handles all beans where we want all methods to use PROPAGATION_REQUIRED -->
      	<bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
      		<property name="interceptorNames">
      			<list>
      			<idref local="matchAllTxInterceptor"/>
      			</list>
      		</property>
      		<property name="beanNames">
      			<list>
      			<idref local="userAdminService"/>
              ...other beans...
      			</list>
      		</property>
      	</bean>
      						
      </beans>
      Here is the HibernateService that returns the SessionFactory. We have a utility class that looks up the HibernateFactory service via JNDI.


      Code:
      <?xml version="1.0" encoding="UTF-8" ?>
      <!DOCTYPE server PUBLIC "-//JBoss//DTD MBean Service 3.2//EN" "http&#58;//www.jboss.org/j2ee/dtd/jboss-service_3_2.dtd">
      <server>
      <mbean code="net.sf.hibernate.jmx.HibernateService" name="jboss.jca&#58;service=HibernateFactory,name=HibernateFactory">
      
          <attribute name="JndiName">java&#58;/hibernate/HibernateFactory</attribute>
      
          <attribute name="Datasource">java&#58;/OracleDS</attribute>
          <attribute name="Dialect">net.sf.hibernate.dialect.Oracle9Dialect</attribute>
      
          <!--attribute name="Datasource">java&#58;/DefaultDS</attribute-->
          <!--attribute name="Dialect">net.sf.hibernate.dialect.HSQLDialect</attribute-->
      
          <attribute name="MapResources">
              com/renewdata/odin/dao/mappings/OdinUser.hbm.xml,
      ...more mappings...
      
          </attribute>
      
          <attribute name="TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactory</attribute>
          <attribute name="TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTransactionManagerLookup</attribute>
          <attribute name="UserTransactionName">UserTransaction</attribute>    
          <attribute name="ShowSql">false</attribute>
          <attribute name="CacheProvider">net.sf.hibernate.cache.EhCacheProvider</attribute>
          
          <depends>jboss.jca&#58;service=RARDeployer</depends>
      
          <!-- Make it deploy ONLY after DataSource had been started -->
          <depends>jboss.jca&#58;service=LocalTxCM,name=OracleDS</depends>
          <!--depends>jboss.jca&#58;service=LocalTxCM,name=DefaultDS</depends-->    
      </mbean>
      </server>
      I would expect Hibernate to listen for the Transaction to commit() and then flush the Session, but this doesn't seem to be happening, even when I specify FlushMode.COMMIT. The server log shows each service method being committed but the database is never being modified.

      Code:
      2005-07-11 15&#58;39&#58;52,093 DEBUG &#91;org.springframework.transaction.interceptor.TransactionInterceptor&#93; Invoking commit for transaction on method 'getConfiguration' in class &#91;com.renewdata.odin.service.IOdinUserAdminService&#93;
      I'm confident that Hibernate is using the Spring Transaction because calling commit() programatically generates a warning that I'm inside a Managed Transaction.

      Any help would be appreciated. Thanks!

      Comment

      Working...
      X