|
DocUpgrade3
This page provides some information that is useful when migrating a project from iBatis 2 to MyBatis 3. It is probably not 100% complete. Conversion ToolThere is a tool available in the downloads section that will help you to convert your iBATIS 2.x sqlmap files into MyBatis 3.x xml mapper files. Get it from http://mybatis.googlecode.com/files/ibatis2mybatis.zip The tool is designed around an xslt transformation and some text replacements packaged in an ant task and tries to deliver a good starting point before the more complex work begins. New DTDsNew sqlMapConfig.xml DTD: <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> New sqlMap (*.map.xml) DTD: <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> Configuration
SettingsWithin the root configuration tag: <settings x="y" foo="bar"/> is now: <settings>
<setting name="x" value="y"/>
<setting name="foo" value="bar"/>
</settings>and <settings useStatementNamespaces="true"/> can be removed, since the use of namespaces has become mandatory. <typeAlias><typeAlias> must be moved out of the <sqlMap> element to <configuration><typeAliases></typeAliases></configuration> <configuration>
<settings>
...
</settings>
<typeAliases>
<typeAlias ... />
</typeAliases>
</configuration><transactionManager> and <dataSource><transactionManager type="JDBC" commitRequired="false">
<dataSource type="your.package.CustomDataSourceFactory" />
</transactionManager>is now: <environments default="env">
<environment id="env">
<transactionManager type="JDBC">
<property name="commitRequired" value="false"/>
</transactionManager>
<dataSource type="your.package.CustomDataSourceFactory" />
</environment>
</environments><sqlMap><sqlMap resource=... /> <sqlMap resource=... /> <sqlMap resource=... /> is now: <mappers>
<mapper resource=... />
</mappers>Mapping
<resultMap id="productRM" class="product" groupBy="id">
<result property="id" column="product_id"/>
<result property="name" column="product_name"/>
<result property="category" column="product_category"/>
<result property="subProducts" resultMap="Products.subProductsRM"/>
</resultMap>New: <resultMap id="productRM" type="product" >
<id property="id" column="product "/>
<result property="name " column="product_name "/>
<result property="category " column="product_category "/>
<collection property="subProducts" resultMap="Products.subProductsRM"/>
</resultMap>Nested resultMapsThese should now be specified using the <association> tag. <resultMap ...>
<result property="client" resultMap="Client.clientRM"/>
...
</resultMap>is now: <resultMap ...>
<association property="client" resultMap="Client.clientRM"/>
...
</resultMap><parameterMap>Although this tag is deprecated, it can be used as in iBatis 2. However for versions up to 3.0.3 there is a bug when using type="map" and not specifying javaType for a parameter. This will result in There is no getter for property named '...' in 'interface java.util.Map'
This should be solved in MyBatis 3.0.4. For versions 3.0.3 and earlier the workaround is to explicitly specify javaType. Inline parameters#value# is now: #{value}jdbcType changesjdbcType="ORACLECURSOR" is now: jdbcType="CURSOR" and jdbcType="NUMBER" is now: jdbcType="NUMERIC" Stored procedures
<procedure id="getValues" parameterMap="getValuesPM">
{ ? = call pkgExample.getValues(p_id => ?) }
</procedure>is now: <select id="getValues" parameterMap="getValuesPM" statementType="CALLABLE">
{ ? = call pkgExample.getValues(p_id => ?)}
</select>If you're calling an insert procedure that returns a value, you can use <select> instead of <insert>, but make sure to specify useCache="false" and flushCache="true". You'll also have to force a commit.
Caching
<cacheModel id="myCache" type="LRU">
<flushInterval hours="24"/>
<property name="size" value="100" />
</cacheModel>is now: <cache flushInterval="86400000" eviction="LRU"/> Note: you can omit eviction="LRU" since it is the default.
Dynamic SQLThe most common dynamic SQL in my project is isNotNull. Here is an example replacement regex: Pattern: <isNotNull.*?property=\"(.*?)\"> </isNotNull> Replacement: <if test="$1 != null"> </if> Also common is the use of isEqual, you can replace this by a similar <if> tag. Java codeSqlMapClient
Custom type handler
Custom data source factoryOld interface: com.ibatis.sqlmap.engine.datasource.DataSourceFactory New interface: org.apache.ibatis.datasource.DataSourceFactory Replace method public void initialize(Map properties) with public void setProperties(Properties props) | |
{quote}Old:
<resultMap id="invoiceRM" type="invoice" extends="Invoice.abstractInvoiceRM">
New:<resultMap id="agreementDetailRM" type="agreement" extends="Agreement.agreementRM">
{qoute}Can you please reuse the same result map for NEW example? It's not the best way to show difference on different result maps
Try this one: http://code.google.com/p/mybatis/issues/detail?id=72 Have fun
Hello. all
I set log4.properties [log4j.rootLogger=debug]
In iBatis2 we had an attribute named nullValue with result tag. Can you please tell what is the migration for myBatis 3.
The migration script will fail with a FileNotFoundException? if your DTD references are out of date. Make sure your DTD references point to ibatis.apache.org (not ibatis.com) before attempting to run the ant script.
In iBatis2 we had an attribute named nullValue with result tag. Can you please tell what is the migration for myBatis 3 ?
Maybe you should try the mailing list, I think you'll have more chance of getting an answer there.
If not I guess you can work around it with a custom type handler.
I would like to know how to use Conversion Tool. please let me know how to convert iBATIS 2.x files into MyBatis? files.
I downloaded ibatis2mybatis.zip file. and read instruction.txt file. There is some information but it is too simple. like below.
Put Your old ibatis2 sqlmap files in the source folder and execute the ant build file.
please can you tell me more details and further information. thank you in advance for your help.
I am having a hard time figuring out how to do batch the stored proc calls in MYBATIS/Spring.
We have used IBATIS/Spring earlier and had used SqlMapExecutor? to start batches and execute the same. MYBATIS doesn't seem to provide similar api. I have tried created Executors of type BATCH as follows :
<bean id="sqlSessionForBatchOperations" class="org.mybatis.spring.SqlSessionTemplate">
</bean>Please provide some insight into this..
In ibatis 2 one could map parameter using nullValue to set a default or alternative for null objects. What happen with it? Is there an equivalent?
Hi Folks,
I'm using the ibatis2mybatis tool to migrate the old iBatis 2.3 xml files to mybatis 3.x.. getting Connection timed out: connect...any ideas? Or even is there a trouble shooting guide?
BUILD FAILED javax.xml.transform.TransformerException?: javax.xml.transform.TransformerException?: com.sun.org.apache.xml.internal.utils.WrappedRuntimeEx? eption: Connection timed out: connect
any of your file DTDs has a wrong url?
Hi eduardo,
The dtd referred to in my iBatis sql-map-config.xml is:
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "http://www.ibatis.com/dtd/sql-map-2.dtd">
..and the dtd referred to in all my iBatis files containing <sqlMap> is
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "http://www.ibatis.com/dtd/sql-map-2.dtd">
..sorry that should have read
<!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-config-2.dtd"> and
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "http://www.ibatis.com/dtd/sql-map-2.dtd">
johnlmorgan: were you able to get past this problem? I'm seeing the same thing and am wondering if it's a proxy server issue...
Spoke too soon! Yep...that was it. Follow the instructions here to get by this error: http://ant.apache.org/manual/proxy.html