Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7442309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:09:18+00:00 2026-05-29T11:09:18+00:00

I want to build an application using Hibernate and MyBatis integrate with Spring. In

  • 0

I want to build an application using Hibernate and MyBatis integrate with Spring. In the prototype i’ve got to run them, but not toghether. My application context of Spring is:

    <?xml version="1.0" encoding="UTF-8"?>
<!--
    Document   : applicationContext-spring.xml
    Created on : 26 de diciembre de 2012, 15:49
    Author     : Pedro Fdez
    Description:
        Fichero de configuración de Spring
-->
<beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:context="http://www.springframework.org/schema/context"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xsi:schemaLocation="http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/aop 
            http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
            http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context-3.0.xsd
            http://www.springframework.org/schema/tx 
            http://www.springframework.org/schema/tx/spring-tx-3.0.xsd" default-autowire="byName">

    <context:annotation-config />
    <context:component-scan base-package="com.administracion.model.dao.implementations" />
    <tx:annotation-driven transaction-manager="txManagerHibernate"/>
    <aop:aspectj-autoproxy />   

    <!-- ............................ -->
    <!-- Configuración de datasource -->
    <!-- ............................ -->
    <bean id="dataSource"
        class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property name="driverClassName" value="${jdbc.driverClassName}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
    </bean>

    <!-- .......................... -->
    <!-- Configuración de Hibernate -->
    <!-- .......................... -->

    <!-- SessionFactory de Hibernate -->
    <bean id="sessionFactoryHibernate"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
            </props>
        </property>

        <property name="packagesToScan">
            <list>
                <value>com.administracion.model.pojos</value>
            </list>
        </property>
    </bean>
    <!-- Gestor transaccional de Hibernate -->
    <bean id="txManagerHibernate"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactoryHibernate"/>
    </bean>

    <!-- ........................ -->
    <!-- Configuración Mybatis -->
    <!-- ........................ -->

    <!-- Gestor transaccional de MyBatis -->
    <bean id="txManagerMyBatis"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>
    <tx:advice id="txAdviceMyBatis" transaction-manager="txManagerMyBatis">
        <tx:attributes>
            <tx:method name="*" />
        </tx:attributes>
    </tx:advice>
    <aop:config>
        <aop:pointcut id="transactionPointCut"
            expression="execution(* com.administracion.model.dao.interfaces.*.*(..))" />
        <aop:advisor advice-ref="txAdviceMyBatis" pointcut-ref="transactionPointCut" />
    </aop:config>

    <!-- SessionFactory de MyBatis -->
    <bean id="sqlSessionFactoryMyBatis" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="configLocation" value="classpath:conf/mybatis/mybatis-config.xml" />
        <property name="dataSource" ref="dataSource" />
    </bean>

    <!-- MapperFactory de Mybatis -->
    <bean id="profesionMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
        <property name="sqlSessionFactory" ref="sqlSessionFactoryMyBatis" />
        <property name="mapperInterface" value="com.administracion.model.dao.mappers.IProfesionMapper" />
    </bean> 


    <bean id="profesionService" class="com.administracion.model.dao.implementations.ProfesionDaoImpl">
        <property name="profesionMapper" ref="profesionMapper" />
    </bean>
    <!-- Declaramos la exportación del servicio vía RMI -->
    <bean class="org.springframework.remoting.rmi.RmiServiceExporter">
        <property name="registryPort" value="${rmi.port.default}"/>
        <!-- Interface del servicio que exportamos -->
        <property name="serviceInterface" value="com.administracion.model.dao.interfaces.IProfesionDao"/>
        <!-- Nombre con que el servicio se va a llamar desde afuera -->
        <property name="serviceName" value="ProfesionService"/>
        <!-- Nombre del bean de la implementación que le hemos dado en el contexto de spring -->
        <property name="service" ref="profesionService"/>
    </bean>

</beans>

In this way, each one have his own transaction manager and session factory. It’s wrong because in a nested transaction can run several transactions, for example:

  1. hibernate transaction
  2. hibernate transaction
  3. mybatis transaction
  4. hibernate transaction

    If mybatis transaction make an exception, it does rollback, but not the hibernate one.

    He’s readen int this forum a thread about how to share transaction between Hibernate and MyBatis, but I don’t understand it.

    Can Somebody tell me about some link, or any information for fix this, please?

    Excuse me for my English. It’s very bad.

    Thanks in advance.

    Pedro J.Fdez.
    Madrid. Spain.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T11:09:21+00:00Added an answer on May 29, 2026 at 11:09 am

    Googling I’ve found a solution for it. Big problems, simple solutions.

    <!-- 
    <bean id="txManagerMyBatis"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>
    --> 
    <tx:advice id="txAdviceMyBatis" transaction-manager="txManagerHibernate">
    

    Basically, to comment de MyBatis transaction manager and to stick it to hibernate one.

    I hope this help somebody.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to build an application using Rails 3.0.1 but do not want to
I want to build an application using Quicktime ActiveX interop that could run on
I want to build a ring topology using android emulators. Currently my application has
I am using cakephp framework to build my application. I want that, whenever a
I am trying to build a WPF application (using C#.net) in which I want
I want to build a Cocoa application using the Model-View-Controller design pattern. I have
I want to build a stateless web application using Java Servlets. Because it's stateless,
i have a problem with my project. I want to build application using air
I want to build a windosform application using Repository and Unit of Work pattern.
I want to build facebook application and I am trying to do it using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.