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

  • HORRIBLE Problem with TransactionProxyFactoryBean

    Hello Everyone:

    I am having a truly gruesome problem with TransactionProxyFactoryBean, and I need some help rather badly. I have used declarative transactions before, and I had a hard time getting everything to work right then. This time, I seem to be totally screwed.

    I am using Hibernate 2.x, Spring 1.0 (also have tried 1.1.5), MySQL, Tomcat 4.1.x. At the moment I am trying to use the prototypical TransactionProxyFactoryBean config, like this:

    * snip *
    <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate.Hibernate TransactionManager">
    <property name="sessionFactory"><ref bean="sessionFactory"/></property>
    </bean>

    <!-- Transaction manager that delegates to JTA (for a transactional JNDI DataSource) -->
    <!-- <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTran sactionManager"/> -->

    <!-- Transactional proxy for CustomerDAO -->
    <bean id="customerDAO" class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager"><ref bean="transactionManager"/></property>
    <property name="target"><ref bean="customerDAOTarget"/></property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <!-- customerDAO: Hibernate implementation -->
    <bean id="customerDAOTarget" class="com.foo.orm.dao.CustomerDAO">
    <property name="sessionFactory"><ref bean="sessionFactory"/></property>
    </bean>

    The above bean config fragment (which is an EXCERPT) is read into my bean factory with the following code:

    ClassPathResource res = new ClassPathResource("hibernate-beans.xml");
    beanFactory = new XmlBeanFactory(res);

    Simple, right? But when I try to get a "customerDAO" bean instance with this code:

    CustomerDAO customerDAO = (CustomerDAO) getBean("customerDAO");

    I get the WRONG CLASS - "$Proxy0" is returned by the bean factory instead of a CustomerDAO instance. Then the above "getBean" statement throws ClassCastException because the wrong type is being cast.

    Please toss me a bone. This is a pretty weird problem, and it definitely seems like this ought to work. I have struggled with this for about a day in various forms, and I am really stuck.
Working...
X