Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: How to use Ibatis in spring framework

  1. #1
    Join Date
    Oct 2005
    Location
    Hyderabad
    Posts
    1

    Default How to use Ibatis in spring framework

    I have to use IBatis with spring framework , please provide sample test example if you can or link to the test sample application.
    Springs Help

  2. #2
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    Please look at the Spring PetClinic sample application. It uses iBATIS and demonstrates Spring's iBATIS integration.
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  3. #3

    Default How to use Ibatis in spring framework

    Hi,

    I have tried to find the PetClinic spring sample application, and I couldn't find it. Do you now other sample or where can I find this sample.

    Thanks

    Rodolfo

  4. #4
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    Sorry, I meant the Pet Store. Apologies for the mistake.
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  5. #5

    Default

    I can't find the Pet Store too in SpringFramework.org. If you were so kind to put a link to this sample I would appreciate.

    Thanks in advance

    Rodolfo

  6. #6
    Join Date
    Feb 2006
    Posts
    3

    Default

    You need to download the latest release from http://www.springframework.org/download

    You'll find the petStore sample application in "spring-framework-1.2.6\samples\jpetstore"

  7. #7
    Join Date
    Jan 2006
    Posts
    20

    Default

    Try these steps:

    1. In the ApplicationContext.xml file, add the following definitions (1 for a Data Source and 1 for the SQL Map Spring Bean)

    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName" value="java:comp/..."/>
    </bean>

    <bean id="sqlMapClient"
    class="org.springframework.orm.ibatis.SqlMapClient FactoryBean">
    <property name="configLocation" value="WEB-INF/sqlmaps.xml"/>
    <property name="dataSource" ref="dataSource"/>
    </bean>

    2. Create a sqlmaps.xml file in the /WEB-INF/ dir. You should be able to get this from the IBATIS Developer guides.
    3. Create Some SQL MAP file that you wish to query from a DB. I would suggest a very simple QUERY to start.
    4. Create a class that extends the Spring File org.springframework.orm.ibatis.support.SqlMapClien tDaoSupport.
    5. Create a method in that class named whatever and put a body similar to the following:

    getSqlMapClientTemplate().queryForXXX(...)

    That should ideally load your SQL MAP configuration at startup, and then allow you to call the SQLMAP query from your java code.

    HTH.

    Daniel

  8. #8
    Join Date
    Jun 2007
    Posts
    3

    Default iBatis + Spring Tutorial


  9. #9

    Default Spring unable to load the actual query maps of iBatis.

    I am having a problem integrating iBatis with Spring.

    In applicationContext, the following entry works fine since it throws an error if the path is incorrect.

    <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClient FactoryBean">
    <property name="configLocation" value="/WEB-INF/sqlmap.xml"/>
    <property name="dataSource" ref="configDataSource" />
    </bean>

    The /WEB-INF/sqlmap.xml looks like this

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE sql-map-config
    PUBLIC "-//iBATIS.com//DTD SQL Map Config 1.0//EN"
    "(omitted because of this forum restriction)/sql-map-config.dtd">
    <sql-map-config>
    <settings useFullyQualifiedStatementNames="true"/>
    <sql-map resource="MyData.xml" />
    </sql-map-config>


    Now the MyData.xml looks like this...

    <?xml version="1.0" encoding="UTF-8" ?>

    <!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
    "(omitted because of this forum restriction)...batis.apache.org/dtd/sql-map-2.dtd">
    <sqlMap namespace="StaticData">
    <!-- Type Alias -->
    <typeAlias alias="city" type="model.City" />

    <!-- Cache Model -->
    <cacheModel id="staticDataCache" type="LRU">
    <flushInterval hours="168" />
    <property name="size" value="100" />
    </cacheModel>
    <!-- Result Maps -->
    <resultMap id="cityResult" class="city">
    <result property="guid" column="GUID" />
    <result property="name" column="NAME" />
    </resultMap>
    <!-- Queries -->
    <select id="getAllCities" resultClass="city" cacheModel="staticDataCache">
    SELECT GUID, NAME FROM CITY </select>
    </sqlMap>


    I am deploying the entire thing in a Struts2 based web application.

    Where should I place MyData.xml file so that it gets picked up.

    It is throwing an exception as:

    com.ibatis.sqlmap.client.SqlMapException: There is no statement named getAllCities in this SqlMap.

  10. #10
    Join Date
    May 2005
    Location
    California, US
    Posts
    735

    Default

    In a directory/folder that's in/on the classpath.

    If you're using eclipse that would be WEB-INF/classes and it'll copy it from there to the right place when you start tomcat (if you're running your test tomcat from within eclipse).

    If you're using maven then put it in src/main/resources, the contents of which are copied to the WEB-INF/classes folder when maven makes the war file.

Similar Threads

  1. Spring MVC Web Framework versus Struts
    By biguniverse in forum Web Flow
    Replies: 27
    Last Post: Aug 29th, 2012, 03:57 AM
  2. Utilize Spring's JDBC Framework or iBATIS
    By jaybytez in forum Data
    Replies: 2
    Last Post: Mar 11th, 2005, 06:24 PM
  3. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM
  4. What's the value-add over Ibatis DAO Framework??
    By Loumeister in forum Architecture
    Replies: 4
    Last Post: Aug 27th, 2004, 11:28 PM

Posting Permissions

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