PDA

View Full Version : Using Hibernate and Ibatis (in the same dao)



GavinLas2
Sep 28th, 2004, 03:45 AM
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.LocalSessionFact oryBean">
<property name="configLocation"><value>/hibernate.cfg.xml</value></property>
</bean>

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

<bean id="dao"
class="org.springframework.transaction.interceptor.Transa ctionProxyFactoryBean"
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>

irbouho
Sep 28th, 2004, 07:05 PM
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>
</bean>
</property>
</bean>

jpetstore sample, from Spring distribution, shows more details on using iBatis with Spring.

HTH

arif6666
Feb 10th, 2006, 04:00 AM
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