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

  • Using Hibernate and Ibatis (in the same dao)

    Hello,

    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.

    Thanks


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

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

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

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

  • #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:
    Code:
      <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>
          </bean> 
        </property> 
      </bean>
    jpetstore sample, from Spring distribution, shows more details on using iBatis with Spring.

    HTH

    Comment


    • #3
      Hi,
      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,
      RF

      Comment

      Working...
      X