Announcement Announcement Module
Collapse
No announcement yet.
ransaction with both Hibernate and JDBC? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ransaction with both Hibernate and JDBC?

    Our application is using lots of session bean which are using CMT and accessing with many DAOs with large legacy code base.

    So we are planning migrate swith from ejbs to Spring pojos at the service layer.

    My problem is accessing the DAO with the spring related trasactions attibutes.I tried with the HibernateTransactionManager it worked well.

    The best solution would be to move everything to Hibernate but this is at the moment not possible (not enough time, too many JDBC DAOs).

    Please help me out with the example having the same set of constraints ?

    My applicationContext.xml

    <bean id="txManager" class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
    <property name="dataSource" ref="myDataSource"/>
    </bean>

    <bean id="customerservice" class="com.CustomerService">
    <property name="customerdao">
    <ref bean="customerdao"/>
    </property>
    </bean>
    <bean id="customerdao" class="com.CustomerDAO">
    <property name="dataSource" ref="myDataSource"/>
    <property name="txManager" ref="txManager"/>
    </bean>

    <tx:advice id="txAdvice1" transaction-manager="txManager">
    <tx:attributes>
    <tx:method name="*" rollback-for="java.sql.SQLException"/>
    </tx:attributes>
    </tx:advice>

    <aop:config>
    <aopointcut id="methods" expression="execution(* com.CustomerService.*(..))"/>
    <aop:advisor advice-ref="txAdvice1" pointcut-ref="methods"/>
    </aop:config>
    Last edited by sdan0316; Nov 2nd, 2009, 11:05 AM.

  • #2
    Use [ code][/code ] tags when posting code !!!!

    Don't mix 2 transaction managers. The HibernateTransactionManager is perfectly capable of managing JDBC transactions.

    Also if you already use CMT then why not simply use a JtaTransactionManager that way it integrates with your session beans as well....

    Comment


    • #3
      I am not using two trasactionManagers.

      Can you please post some sample code with managing the trasaction with the spring by using the old JDBC code

      Comment


      • #4
        Here I am pasting my applicationContext.xml

        <code>

        <bean id="txManager" class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
        <property name="dataSource" ref="myDataSource"/>
        </bean>

        <bean id="customerservice" class="com.CustomerService">
        <property name="customerdao">
        <ref bean="customerdao"/>
        </property>
        </bean>
        <bean id="customerdao" class="com.CustomerDAO">
        <property name="dataSource" ref="myDataSource"/>
        <property name="txManager" ref="txManager"/>
        </bean>

        <tx:advice id="txAdvice1" transaction-manager="txManager">
        <tx:attributes>
        <tx:method name="*" rollback-for="java.sql.SQLException"/>
        </tx:attributes>
        </tx:advice>

        <aop:config>
        <aopointcut id="methods" expression="execution(* com.CustomerService.*(..))"/>
        <aop:advisor advice-ref="txAdvice1" pointcut-ref="methods"/>
        </aop:config>

        </code>

        And I have extended my CustomerDAO with JDBCDAOSupport .
        When I am trying to execute the query getJdbcTemplate().update its not able to find out the JDBCtemplate Object.
        Please help me out

        Comment


        • #5
          DataSource Definition

          Hi,

          You have not provided your datasource definition in the xml file.
          Maybe the datasource information is incomplete.

          Regards,
          Rajiv

          Comment

          Working...
          X