Announcement Announcement Module
No announcement yet.
BeanNameAutoProxyCreator doesn't wrap all methods? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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?


    • #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:

      <?xml version="1.0" encoding="UTF-8" ?>
      <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http&#58;//">
      <!-- This is the EJB-centric application context that will be loaded by -->
      <!-- the Spring bean factory locator                                    -->
      	<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
      		<property name="userTransactionName">
      	<bean id="userAdminService" 
      ...other beans...	
      	<!-- Transaction Interceptor set up to do PROPAGATION_REQUIRED on all methods -->
      	<bean id="matchAllWithPropReq" 
      		<property name="transactionAttribute">
      	<bean id="matchAllTxInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
      		<property name="transactionManager">
      			<ref bean="transactionManager"/>
      		<property name="transactionAttributeSource">
      			<ref bean="matchAllWithPropReq"/>
      	<!-- 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">
      			<idref local="matchAllTxInterceptor"/>
      		<property name="beanNames">
      			<idref local="userAdminService"/>
              ...other beans...
      Here is the HibernateService that returns the SessionFactory. We have a utility class that looks up the HibernateFactory service via JNDI.

      <?xml version="1.0" encoding="UTF-8" ?>
      <!DOCTYPE server PUBLIC "-//JBoss//DTD MBean Service 3.2//EN" "http&#58;//">
      <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">
      ...more mappings...
          <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>
          <!-- Make it deploy ONLY after DataSource had been started -->
      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.

      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!