I have to use IBatis with spring framework , please provide sample test example if you can or link to the test sample application.
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
Please look at the Spring PetClinic sample application. It uses iBATIS and demonstrates Spring's iBATIS integration.
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
Sorry, I meant the Pet Store. Apologies for the mistake.
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
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"
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
Try this iBatis-Spring Tutorial http://www.developersbook.com/ibatis...-tutorials.php
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.
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.