Results 1 to 3 of 3

Thread: Using Hibernate and Ibatis (in the same dao)

  1. #1
    Join Date
    Aug 2004
    Posts
    2

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    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
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  3. #3
    Join Date
    Feb 2006
    Posts
    5

    Default

    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

Similar Threads

  1. Replies: 8
    Last Post: Sep 7th, 2005, 03:38 PM
  2. Hibernate and iBatis
    By stateofmind in forum Data
    Replies: 6
    Last Post: Aug 22nd, 2005, 05:38 AM
  3. Hibernate or iBatis
    By jaybytez in forum Data
    Replies: 2
    Last Post: Feb 25th, 2005, 04:59 AM
  4. Replies: 2
    Last Post: Dec 10th, 2004, 09:47 AM
  5. Replies: 1
    Last Post: Dec 8th, 2004, 11:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •