Announcement Announcement Module
No announcement yet.
Using Hibernate and Ibatis (in the same dao) Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using Hibernate and Ibatis (in the same dao)


    I have Hibernate set up via Spring as follows... I would like to set up ibatis so I can use both libraries in my daos. What do I need to do to configure ibatis to use hibernate connections and transactions. What else do I need to share between these 2 frameworks.


    <!-- Hibernate -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSess ionFactoryBean">
    <property name="configLocation"><value>/hibernate.cfg.xml</value></property>

    <bean id="transactionManager" class="org.springframework.orm.hibernate.Hibernate TransactionManager">
    <property name="sessionFactory">
    <ref bean="sessionFactory"/>

    <bean id="dao"
    class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean"
    <property name="transactionManager"><ref bean="transactionManager"/></property>
    <property name="transactionAttributes">
    <prop key="update*">PROPAGATION_REQUIRED</prop>
    <prop key="save*">PROPAGATION_REQUIRED</prop>
    <prop key="delete*">PROPAGATION_REQUIRED</prop>
    <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>

    <bean id="oneDao" parent="dao">
    <property name="target">
    <bean class="dao.service.OneDaoImpl">
    <property name="sessionFactory"><ref bean="sessionFactory"/></property>

  • #2
    iBatis based DAOs can share Hibernate connections and transactions out of the box. All you need to do is configure the same DataSource for Hibernate DAOs and iatis DAOs, and using HibernateTransactionManager to handle iBatis DAO transactions:
      <bean id="anotherDao" parent="dao"> 
        <property name="target"> 
          <bean class="dao.service.anotherDaoImpl"> 
            <property name="dataSource"><ref local="dataSource"/></property>
            <property name="sqlMap"><ref local="sqlMap"/></property>
    jpetstore sample, from Spring distribution, shows more details on using iBatis with Spring.



    • #3
      I am new to Ibatis and I am trying a scenario of,

      Spring Core/Context -> iBatis DAO -> Hibernate -> Oracle DB

      i.e., In a Spring context i am trying to use Ibatis DAO to access Hibernate.

      If any one has any sample implementation for the above case or any useful link for the same, kindly do post it.

      This case is taken from Ibatis definition,
      " The iBATIS Data Access Objects API can be used to help hide persistence layer implementation details

      from the rest of the application by allowing dynamic, pluggable DAO components to be swapped in and

      out easily. For example, you could have two implementations of a particular DAO, one that uses the

      iBATIS SQL Maps framework to persist objects to the database, and another that uses the Hibernate framework

      Kindly help!

      Thanks and Regards,