Announcement Announcement Module
Collapse
No announcement yet.
Spring Core/Context -> iBatis DAO -> Hibernate Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Core/Context -> iBatis DAO -> Hibernate

    Hi,
    I am trying Ibatis DAO using Spring.
    My understanding is, with Ibatis DAO we can have implementation of our DAO using Ibatis SQL Maps or Hibernate Framework.
    I would like to try the second option of , Ibatis DAO to look into Hibernate framework, and this to happen in a Spring context.
    Kindly help, by sending any useful link on this topic or provide some sample implementation.

    I have tried the first option , and working fine
    Spring Core/Context -> iBatis DAO -> Ibatis SQL Map

    Here are the implementation detail for First Option,

    ibatis-config.xml
    ***********
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE sqlMapConfig
    PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
    "http://www.ibatis.com/dtd/sql-map-config-2.dtd">
    <sqlMapConfig>
    <sqlMap resource="Site.xml"/>
    </sqlMapConfig>

    Site.xml
    ******

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE sqlMap
    PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
    "http://www.ibatis.com/dtd/sql-map-2.dtd">

    <sqlMap namespace="Site">

    <typeAlias alias="siteCustomer" type="com.ra.rs.common.dto.SiteCustomer"/>

    <resultMap id="siteCustomerResult" class="siteCustomer">
    <result property="siteID" column="SITE_ID" />
    <result property="siteStatus" column="SITE_STATUS" />
    <result property="customerID" column="CUSTOMER_ID" />
    <result property="customerStatus" column="CUSTOMER_STATUS" />
    </resultMap>

    <select id="getSiteCustomer" resultMap="siteCustomerResult">

    SELECT S.SITE_ID, S.STATUS AS SITE_STATUS, CU.CUSTOMER_ID, CU.STATUS AS CUSTOMER_STATUS FROM RCAS_SITE_MST S, RCAS_CUSTOMER_MST CU WHERE S.CUSTOMER_ID = CU.CUSTOMER_ID ORDER BY SITE_ID

    </select>
    </sqlMap>

    DAO Implementation class
    *******************

    public class IbatisSiteDAOImpl extends SqlMapClientDaoSupport implements ISiteDAO {

    /** Logger Instance */
    private static Log log = LogFactory.getLog(IbatisSiteDAOImpl.class);


    public List getAllSiteCustomer() throws RCASException
    {
    List siteCustomerList = null;

    if(log.isDebugEnabled())
    {
    log.debug("Inside getAllSiteCustomer() of IbatisSiteDAOImpl");
    }

    siteCustomerList = getSqlMapClientTemplate().queryForList("getSiteCus tomer",null);
    System.out.println("Output from Site DAO"+siteCustomerList);

    if(log.isDebugEnabled())
    {
    log.debug("Coming Out of getAllSiteCustomer() of IbatisSiteDAOImpl");
    }

    return siteCustomerList;
    }

    ***********************

    Spring-Context.xml
    **************

    <!--Data Source-->
    <bean id="RSDataSource" class="org.springframework.jndi.JndiObjectFactoryB ean" lazy-init="true">
    <property name="jndiName">
    <value>RSDev</value>
    </property>
    </bean>

    <bean id="siteDaoImpl" class="com.ra.rs.common.dao.ibatisImpl.IbatisSiteD AOImpl">
    <property name="dataSource"><ref local="RSDataSource"/></property>
    <property name="sqlMapClient"><ref local="sqlMapClient"/></property>
    </bean>

    <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClient FactoryBean">
    <property name="configLocation">
    <value>ibatisConfig.xml</value>
    </property>
    </bean>

    <!--Defines the Transaction Template-->
    <bean id="TransactionTemplate" class="org.springframework.transaction.support.Tra nsactionTemplate">
    <property name="transactionManager">
    <ref bean="TransactionManager"/>
    </property>
    </bean>

    <!--Defines the Transaction Manager-->
    <bean id="TransactionManager" class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
    <property name="dataSource">
    <ref bean="RCASDataSource"></ref>
    </property>
    </bean>

    ************************************************** ****

    Kindly help to try the Second option,

    Spring Core/Context -> iBatis DAO -> Hibernate

    Thanks & Regards,
    RF
Working...
X