﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-&lt;b&gt;成都心情&lt;/b&gt;-随笔分类-O/R Mapping</title><link>http://www.blogjava.net/rosen/category/2688.html</link><description>本 Blog 是从：http://blog.csdn.net/rosen 搬来。&lt;br/&gt;</description><language>zh-cn</language><lastBuildDate>Sun, 02 Mar 2008 11:56:21 GMT</lastBuildDate><pubDate>Sun, 02 Mar 2008 11:56:21 GMT</pubDate><ttl>60</ttl><item><title>Apache Cayenne—辣椒你吃了吗？</title><link>http://www.blogjava.net/rosen/archive/2006/07/31/60972.html</link><dc:creator>Rosen</dc:creator><author>Rosen</author><pubDate>Mon, 31 Jul 2006 03:10:00 GMT</pubDate><guid>http://www.blogjava.net/rosen/archive/2006/07/31/60972.html</guid><wfw:comment>http://www.blogjava.net/rosen/comments/60972.html</wfw:comment><comments>http://www.blogjava.net/rosen/archive/2006/07/31/60972.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/rosen/comments/commentRss/60972.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rosen/services/trackbacks/60972.html</trackback:ping><description><![CDATA[
		<p>    Apache Cayenne 是一个强大而易于掌握的 Java  ORM 框架。它是开源且完全免费的。Cayenne 提供了 Java 对象到关系型数据库的持久化映射管理，单方法调用查询和更新（包括细粒度的更新所有被修改的对象），无缝隙的把多种数据库集成到单一虚拟数据源中。Cayenne 由 CayenneModeler 分配——完整的 GUI 映射工具。Cayenne 已被成功部署在高负载的生产环境中。<br />    <br />    在吸取了广大用户的建议的基础上发布了 1.2 版本。这个版本中最重要的新特性是“远程对象持久化(Remote Object Persistence)”，就是把 Cayenne 转变成一个独立的数据服务器，以便远程应用能访问。目前，仅仅用于 Java 客户端程序（常常用于 Swing 或 SWT“富客户端”应用），但开发者计划将客户端用其他语言来实现。ORM-到-WS 把熟悉的 ORM 世界提供给远程客户端。即关系的延迟粒度、本地缓存、数据请求、单方法调用多对象的提交、等等。也就是服务器和客户端层共享同样的抽象对象模型和相同的 Cayenne 持久 API。<br />    <br />    Cayenne 最早由几名程序员在 2001 年的亚特兰大构思。这个项目目的在于构建一个开源的 ORM 框架（当时还没有这样的产品），最初的设计灵感源于 NeXT/Apple 企业对象架构（Enterprise Objects Framework,EOF）。在 2002 年的秋天，Cayenne 1.0 alpha 版成功地在 NHL.com 网站（全国曲棍球联合会）上运用。第一个官方稳定版在 2003 年 9 月发布。从那以后，Cayenne 就在全球大大小小的组织（译注：这些机构、组织的网站）上部署。2006 年春，Cayenne 被接纳为 Apache 软件基金会孵化器项目，并立志成为 Apache 项目（译注：也许是指和 iBATIS 一样）。<br />    <br />    在了解了 Cayenne 的前世今生后，来听听用户的声音。<br />    <br />     “我们使用 Cayenne 已经有 6 个月了，基于这个框架构建了多个 web 应用，发现它是一种生产效率很高的工具。基于 Cayenne 建模和开发是非常神奇的事情。你可以创建新表或更新已存在的表，接着点击很少的按钮你的数据库就构建好了，所有类也生成了。在进行程序快速开发时，这一分钟的持久化变动是非常有效率的。下面我把 Cayenne 1.2 和 Hibernate 3.0 做一比较：Cayenne 是更有生产力的工具集，主要是由于它的数据库生成和代码生成特性上，用户无需书写和维护 XML 映射文件。而 Hibernate 有着更加强大的查询语言。Cayenne 的设计更加适合 web 应用程序。对于 ThreadLocal 和 HttpSession 的支持，事务模式以及连接池都可以直接拿来就用。如果是 Hibernate 的话，用户必须自己找这些插件或者利用 Spring 对 Hibernate 的支持。Cayenne 的 DataObjects 一直都处于连接状态，无需遭受 Hibernate 的“lazy initialization exception”之苦。Hibernate 更好的支持了 PK 和 FK 设计的关联数据表。如果用户遵循设计模式，在 Cayenne 中也可以直接用 PK 代理。”<br />                                                                                                    —— Malcolm Edgar<br />      <br />    “我想最好的特性是无需关闭数据库连接或会话。如果我使用 Hibernate，我必须手工关闭会话（我没用 springframework），这样太繁琐了，而且容易误操作。换成 Cayenne 的话，我无需关心数据库连接或 JDBC 异常。”<br />                                                                                                    —— lyo Yashnoo<br />    <br />    “我用 Cayenne 差不多一年半了，我想说的是真的太好了！建模工具很强大并且架构也非常成熟、高效！”<br />                                                                                                    —— Pedro Costa<br /><br /><br /><strong><font face="Arial" color="#ff0000" size="2">请注意！引用、转贴本文应注明原作者：Rosen Jiang 以及出处：</font></strong><a href="/rosen"><font face="宋体" color="#ff0000" size="2"><strong>http://www.blogjava.net/rosen</strong></font></a></p>
<img src ="http://www.blogjava.net/rosen/aggbug/60972.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rosen/" target="_blank">Rosen</a> 2006-07-31 11:10 <a href="http://www.blogjava.net/rosen/archive/2006/07/31/60972.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Hibernate 3 Formulas（翻译）</title><link>http://www.blogjava.net/rosen/archive/2005/09/19/13317.html</link><dc:creator>Rosen</dc:creator><author>Rosen</author><pubDate>Sun, 18 Sep 2005 16:08:00 GMT</pubDate><guid>http://www.blogjava.net/rosen/archive/2005/09/19/13317.html</guid><wfw:comment>http://www.blogjava.net/rosen/comments/13317.html</wfw:comment><comments>http://www.blogjava.net/rosen/archive/2005/09/19/13317.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.blogjava.net/rosen/comments/commentRss/13317.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rosen/services/trackbacks/13317.html</trackback:ping><description><![CDATA[<P>&nbsp;&nbsp;&nbsp; <A href="http://www.hibernate.org/">Hibernate</A> 和 <A href="http://www.springframework.org/">Spring</A> 这两个突出的开源框架被越来越多的应用到 J2EE 中。尽管目标有着不同的问题空间，它们却共享一个关键特性：<A href="http://martinfowler.com/articles/injection.html">依赖注入</A>。在对象返回到客户端之前 Spring 协助挑选出这些对象间依赖关系，减少客户端代码量。而 Hibernate 专门挑选出在完整的对象模型返回客户端之前由数据模型表现的依赖关系。当使用 JDBC 直接从数据模型映射到对象模型时，我们通常需要书写大量的代码来构建对象模型。Hibernate 的出现淘汰了这种繁琐的编码工作。<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Hibernate 2.x 提供基本的表到对象的映射，标准关联映射（包括 one-to-one, one-to-many 以及 many-to-many 关系），多态映射，等等。Hibernate 3.x 沿着路线继续前进，formula、filter、subselect 等，使映射更加灵活，提供用细粒度的解释特性。<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; 在本文中，将阐述 formula 到底有哪些特性可帮助我们进行模型转换。Hibernate 3.x 之前，formula 属性只能出现在 property 元素中。但是到了现在，你可以在许多元素中使用 Hibernate 3.x 提供的 formula 属性或元素（formula 用法方面都是一样的），包括 discriminator、element、many-to-many、map-key、map-key-many-to-many、以及 property。它增加了 OR 映射的灵活性，因此允许对复杂数据模型更加细粒的解释。<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; 下面有两个 formula 应用场景：<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; 1. formula 用于评估结果的场合。在 discriminator、element、map-key、map-key-many-to-many以及 property 元素中注入 formula。<BR>&nbsp;&nbsp;&nbsp; 2. formula 用于连接目的的场合。在 many-to-one、one-to-one 以及 many-to-many 元素中注入 formula。<BR>&nbsp;&nbsp;&nbsp; <BR><FONT size=4><STRONG>范畴 1：从 formula 获得评估结果</STRONG><BR></FONT>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; <STRONG>Discriminator<BR></STRONG>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; 在真实的数据 schema 中，经常出现一个表被用于描述其他表的情况。formula 可协助提供灵活的多态 OR 映射。<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; 在图 1 的范例中，有两个表：Product 和 ProductRelease。每条 product 记录都有一个 ProductReleaseID 参考相应的产品出厂记录，包括 product release name、type、release date 等等。<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <IMG height=338 alt="Product and Product Release Data Model" src="http://www.onjava.com/onjava/2005/08/03/graphics/image001.jpg" width=344><BR>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 图 1. Product 和 product release<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; ProductRelease 表中有个有趣的属性 SubProductAllowable，该属性的值为 1 或 0。值为 1 代表允许任何的次品出厂，但是 0 不允许次品出厂。<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; 图 2 展示了由数据模型解释的对象模型。Nested 接口定义了 getSubProducts 和 setSubProducts 方法。NestedProduct 类继承 Product 基类并实现 Nested 接口。无论产品数据记录是 Product 或 NestedProduct，都取决于产品出厂记录中 SubProductAllowable 的值。<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <IMG height=333 alt="Product and Product Release Object Domain Model" src="http://www.onjava.com/onjava/2005/08/03/graphics/image002.jpg" width=375><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 图 2. Product 和产品出厂对象域模型<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; 为了完成模型转换，我们使用如下的 Hibernate 3.x 映射：<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR><FONT color=#000080><HIBERNATE-MAPPING></P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">hibernate-mapping</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">class&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="Product"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;discriminator-value</SPAN><SPAN style="COLOR: #0000ff">="0"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;&nbsp;lazy</SPAN><SPAN style="COLOR: #0000ff">="false"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">id&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="id"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;type</SPAN><SPAN style="COLOR: #0000ff">="long"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">discriminator&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #ff0000">formula</SPAN><SPAN style="COLOR: #0000ff">="(select&nbsp;pr.SubProductAllowable&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from&nbsp;ProductRelease&nbsp;pr&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;where&nbsp;pr.productReleaseID=<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;productReleaseID)"</SPAN><SPAN style="COLOR: #ff0000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type</SPAN><SPAN style="COLOR: #0000ff">="integer"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">subclass&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="NestedProduct"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;discriminator-value</SPAN><SPAN style="COLOR: #0000ff">="1"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">class</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">hibernate-mapping</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></DIV>
<P></FONT>&nbsp;&nbsp;&nbsp; 如果 formula 表达式评估结果为 0 时－－也就是不允许次品出厂－－那么对象将是 Product 类。如果结果是 1，那么对象将是 NestedProduct。在表 1 和 2 中，表 Product 的第一条记录（ProductID=10000001），已初始化的类将是 NestedProduct，因为它参考一条 SubProductAllowable=1 的 ProductRelease 记录。表 Product 的第二条记录（ProductID=20000001），已初始化的类将是 Product，因为它参考一条 SubProductAllowable=0 的 ProductRelease 记录。<BR>&nbsp;&nbsp;&nbsp; 
<TABLE width="46%" border=1>
<TBODY>
<TR>
<TD width="10%">S/N</TD>
<TD width="35%"><CODE><FONT color=#003366>ProductReleaseID</FONT></CODE></TD>
<TD width="35%"><CODE><FONT color=#003366>SubProductAllowable</FONT></CODE></TD>
<TD width="20%">...</TD></TR>
<TR>
<TD>1</TD>
<TD>11</TD>
<TD>1</TD>
<TD>¡&shy;</TD></TR>
<TR>
<TD>2</TD>
<TD>601</TD>
<TD>0</TD>
<TD>¡&shy;</TD></TR></TBODY></TABLE>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 表 1. ProductRelease 表中的记录<BR>&nbsp;&nbsp;&nbsp; 
<TABLE width="46%" border=1>
<TBODY>
<TR>
<TD width="10%">S/N</TD>
<TD width="35%"><CODE><FONT color=#003366>ProductID</FONT></CODE></TD>
<TD width="35%"><CODE><FONT color=#003366>ProductReleaseID</FONT></CODE></TD>
<TD width="20%">...</TD></TR>
<TR>
<TD>1</TD>
<TD>10000001</TD>
<TD>11</TD>
<TD>¡&shy;</TD></TR>
<TR>
<TD>2</TD>
<TD>20000001</TD>
<TD>601</TD>
<TD>...</TD></TR></TBODY></TABLE>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 表 2. Product 表中的记录<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; <STRONG>Property<BR></STRONG>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; 在 property 元素中的 formula 允许对象属性包含特定引伸值，比如对结果进行 sum、average、max 等等。</P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">property&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="averagePrice"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;formula</SPAN><SPAN style="COLOR: #0000ff">="(select&nbsp;avg(pc.price)&nbsp;from&nbsp;PriceCatalogue&nbsp;pc,&nbsp;SelectedItems&nbsp;si&nbsp;where&nbsp;si.priceRefID=pc.priceID)"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN></DIV>
<P>&nbsp;&nbsp;&nbsp; 此外，formula 也能协助从基于当前记录的特定值向其它表检索数据。例如：</P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">property&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="currencyName"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;formula</SPAN><SPAN style="COLOR: #0000ff">="(select&nbsp;cur.name&nbsp;from&nbsp;currency&nbsp;cur&nbsp;where&nbsp;cur.id=&nbsp;currencyID)"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN></DIV>
<P>&nbsp;&nbsp;&nbsp; 这将由助于从 currency 表检索 currency name。正如你所看到的，这样直接映射可消除许多转换编码。<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; <STRONG>map-key</STRONG><BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; formula 允许 map-key 持有任何可能的值。下列范例（图 3），我们想让 Role_roleID 成为对象模型的 map-key（图 4）。<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <IMG height=417 alt="User Role Data Schema" src="http://www.onjava.com/onjava/2005/08/03/graphics/image003.jpg" width=316>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 图 3. 用户角色数据 schema<BR><BR>&nbsp;&nbsp; <IMG height=180 alt="User Role Object Model" src="http://www.onjava.com/onjava/2005/08/03/graphics/image004.jpg" width=431><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;图 4. 用户角色对象模型<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; 在前面的数据 schema 中，User 和 Role 由 User_has_Role 通过 many-to-many 关系关联调用。为了获取某个 User 所有的指派角色，我们进行如下映射：<FONT color=#000080><HIBERNATE-MAPPING></P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">hibernate-mapping</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">class&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="User"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">id&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="userID"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">map&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="roles"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;table</SPAN><SPAN style="COLOR: #0000ff">="UserRole"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">key&nbsp;</SPAN><SPAN style="COLOR: #ff0000">column</SPAN><SPAN style="COLOR: #0000ff">="User_userID"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">map-key&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #ff0000">formula</SPAN><SPAN style="COLOR: #0000ff">="Role_RoleID"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type</SPAN><SPAN style="COLOR: #0000ff">="string"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">many-to-many&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #ff0000">column</SPAN><SPAN style="COLOR: #0000ff">="Role_RoleID"</SPAN><SPAN style="COLOR: #ff0000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;class</SPAN><SPAN style="COLOR: #0000ff">="Role"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">map</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">class</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">class&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="Role"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">id&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="roleID"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">class</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">hibernate-mapping</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></DIV>
<P></FONT>&nbsp;&nbsp;&nbsp; Role_RoleID 通常用于连接 many-to-many 元素的栏位值。Hibernate 通常不允许 Role_RoleID 出现在 map-key 和 many-to-many 的栏位属性中。但是有了 formula，Role_RoleID 也能用于 map-key。<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; <STRONG>element、map-key-many-to-many 以及其他<BR></STRONG>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; element 和 property 类似，能从任何有效的 formula 表达式赋予评估值。<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; map-key-many-to-many 中 formula 的用法类似于 map-key。但是，map-key-many-to-many 通常用于三重关系，map key 是一个被自己参考的对象，而不是被参考的属性。<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; 那么，到底哪些情况下 formula 不支持呢？有些数据库（例如 Oracle 7）就不支持嵌入式 select 语句（也就是说一条 select SQL 内嵌在另外一条 select SQL 语句中），这种情况 formula 就不支持评估结果。因此，你应该首先检查嵌入式 select SQL 语句是否被支持。<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; 一旦 Hibernate 的映射拿 formula 表达式作为 select SQL 选取的一部分，请确认数据库 SQL 方言是否允许使用 formula，尽管这样将降低代码轻便性。<BR>&nbsp;&nbsp;&nbsp; <BR><STRONG><FONT size=4>范畴 2：formula 用于连接</FONT></STRONG></P>
<P>&nbsp;&nbsp;&nbsp; <STRONG>many-to-one<BR></STRONG>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; 另一个普遍的场景是真实世界的数据模型是所有者关系映射，这意味着映射是不同于 one-to-one、one-to-many 以及 many-to-many 关系的，formula 是提供所有者关系管理元素中的一个。图 5 展示了某公司可有多个联系人，但是其中只有一个为默认联系人的范例。一个公司有多个联系人是典型的 one-to-many 关系。但是，为了标识默认联系人，ContactPerson 表使用了 defaultFlag 参数（1 是 yes, 0是 no）。<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <IMG height=327 src="http://www.onjava.com/onjava/2005/08/03/graphics/image005.jpg" width=272><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;图 5. 用户角色数据 schema<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <IMG height=121 src="http://www.onjava.com/onjava/2005/08/03/graphics/image006.jpg" width=281><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 图 6. 用户角色对象模型<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; 为了说明对象模型（图 6）中默认联系人关系，我们使用如下映射文件：<FONT color=#000080></P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">hibernate-mapping</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">class&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="Company"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;table</SPAN><SPAN style="COLOR: #0000ff">="Company"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">id&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="id"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">many-to-one&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="defaultContactPerson"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;property-ref</SPAN><SPAN style="COLOR: #0000ff">="defaultContactPerson"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">column&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="id"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">formula</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">formula</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">many-to-one</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">class</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">class&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="Person"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">id&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="id"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">properties&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="defaultContactPerson"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">property&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="companyID"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">property&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="defaultFlag"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">properties</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">class</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">hibernate-mapping</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></DIV>
<P></FONT>&nbsp;&nbsp;&nbsp; 如上，我们把 companyID 和 defaultFlag 组织到名为 defaultContactPerson 的 properties 元素中，做为 Person 表的 unique key。Company 类中的 many-to-one 元素连接 Person 表的 defaultContactPerson properties 元素。输出的 SQL 像这样：<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; <FONT color=#000080>select c.id, p.id from Company c, Person p where p.companyID=c.id and p.defaultFlag=1<BR></FONT>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; <STRONG>one-to-one</STRONG><BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Hibernate 中，one-to-one 主要用于两张表共享同一主键的情况。对于外键关联，我们通常使用 many-to-one 来代替。但是，有了 formula，one-to-one 可以通过外键连接表。上面的 many-to-one 范例可以通过 one-to-one 来映射：</P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">hibernate-mapping</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">class&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="Company"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;table</SPAN><SPAN style="COLOR: #0000ff">="Company"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">id&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="id"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">one-to-one&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="defaultContactPerson"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;property-ref</SPAN><SPAN style="COLOR: #0000ff">="defaultContactPerson"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">formula</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">id</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">formula</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">formula</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">formula</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">one-to-one</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">class</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">class&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="Person"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">id&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="id"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">properties&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="defaultContactPerson"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">property&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="companyID"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">property&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="defaultFlag"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">properties</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">class</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">hibernate-mapping</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></DIV>
<P>&nbsp;&nbsp;&nbsp; <STRONG>many-to-many<BR></STRONG>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; formula 用于当 many-to-many 元素为关系表和实体表连接的特殊关系，尽管通常没有必要这样用。<BR>&nbsp;&nbsp;&nbsp; <BR><STRONG><FONT size=4>总结</FONT></STRONG></P>
<P>&nbsp;&nbsp;&nbsp; 文章范例展示了大部分 formula 的适用情景。当需要 formula 评估值时，formula 表达式将出现在 产生的 SQL 语句的 select 部分。当 formula 用于连接时，它出现在产生的 SQL 语句的 where 部分。此外，formula 表达式可用于任何 SQL 方言，只要目标数据库支持。最后，formula 可协助完成从数据模型到对象模型的无代码细粒度映射。<BR><BR><BR><STRONG><FONT face=宋体 color=#ff0000 size=2>请注意！引用、转贴本文应注明原译者：Rosen Jiang 以及出处：</FONT></STRONG><A href="http://www.blogjava.net/rosen/rosen/rosen/rosen"><FONT face=宋体 color=#ff0000 size=2><STRONG>http://www.blogjava.net/rosen</STRONG></FONT></A></P><img src ="http://www.blogjava.net/rosen/aggbug/13317.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rosen/" target="_blank">Rosen</a> 2005-09-19 00:08 <a href="http://www.blogjava.net/rosen/archive/2005/09/19/13317.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>iBATIS 动向</title><link>http://www.blogjava.net/rosen/archive/2005/08/12/9938.html</link><dc:creator>Rosen</dc:creator><author>Rosen</author><pubDate>Fri, 12 Aug 2005 07:12:00 GMT</pubDate><guid>http://www.blogjava.net/rosen/archive/2005/08/12/9938.html</guid><wfw:comment>http://www.blogjava.net/rosen/comments/9938.html</wfw:comment><comments>http://www.blogjava.net/rosen/archive/2005/08/12/9938.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rosen/comments/commentRss/9938.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rosen/services/trackbacks/9938.html</trackback:ping><description><![CDATA[<P><FONT size=2>&nbsp;&nbsp;&nbsp; 今年年初，有幸接触到了 iBATIS，并花了数个星期来写了点使用心得（</FONT><FONT size=2><A href="http://www.blogjava.net/rosen/archive/2005/08/12/9931.html">http://www.blogjava.net/rosen/archive/2005/08/12/9931.html</A></FONT><FONT size=2>）。半年多过去，iBATIS 发生了很大的变化，2005 年 5月 1 日，iBATIS 孵化成功，今天已正式成为 Apache 官方项目， </FONT><A href="http://www.ibatis.com/"><FONT size=2>http://www.ibatis.com</FONT></A><FONT size=2> 域名已重定向到 </FONT><A href="http://ibatis.apache.org/"><FONT size=2>http://ibatis.apache.org</FONT></A><FONT size=2>。说说变化吧，iBATIS 产品系列中，iBATIS SQL Maps 更名为 iBATIS Data Mapper 分为 for .NET 和 for Java 两个版本；iBATIS DAO 的名称未变，在原有 for Java 的基础上增加了 for .NET 版本；当然最后还包括官方的 iBATIS PetStore 范例。<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <IMG alt="" src="http://ibatis.apache.org/flow.jpg"><BR>&nbsp;&nbsp;&nbsp; 目前 iBATIS Data Mapper for Java（以下简称:iBATIS Data Mapper）的版本为 2.1.5。当前以及未来的 iBATIS Data Mapper 将加入以下新特征。<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; </FONT><FONT size=2><STRONG><FONT size=3>来自第三方的贡献</FONT><BR></STRONG>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Alex Egorov 的 SQL Map 生成器（</FONT><A href="http://alxeg.narod.ru/ibatis/index.html"><FONT size=2>http://alxeg.narod.ru/ibatis/index.html</FONT></A><FONT size=2>）。Alex 创建了一些便利的脚本来生成你所有的 SQL Maps 和 VO。如果你正在寻找这种快速开发工具，它将是个可以一试的工具。这个站点有点慢，但是这点等待总比你手工编码的时间来得快。<BR>&nbsp;&nbsp;&nbsp; DDL如下：</FONT></P>
<P>
<TABLE style="WIDTH: 568px; HEIGHT: 113px" cellSpacing=1 cellPadding=1 width=568 border=1>
<TBODY>
<TR>
<TD>
<P><FONT size=2>&nbsp;CREATE TABLE USER_PROPERTY (&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; USER_ID BIGINT NOT NULL, <BR>&nbsp;&nbsp;&nbsp; FIRST_NAME VARCHAR(100) DEFAULT '', <BR>&nbsp;&nbsp;&nbsp; LAST_NAME VARCHAR(100), <BR>&nbsp;&nbsp;&nbsp; BIRTH_DATE TIMESTAMP(8), <BR>&nbsp;&nbsp;&nbsp; PRIMARY KEY (USER_ID)<BR>);</FONT></P></TD></TR></TBODY></TABLE></P>
<P><FONT size=2>VO如下：</FONT></P>
<P>
<TABLE style="WIDTH: 567px; HEIGHT: 743px" cellSpacing=1 cellPadding=1 width=567 border=1>
<TBODY>
<TR>
<TD>
<P><FONT size=2>&nbsp;package org.mystuff.db;<BR><BR><BR>// WARNING: This is an autogenerated file<BR><BR><BR>public class UserProperty {<BR><BR>&nbsp;&nbsp;&nbsp; // Constructors<BR>&nbsp;&nbsp;&nbsp; public UserProperty() {<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; public UserProperty(long _userId) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.userId = _userId;<BR>&nbsp;&nbsp;&nbsp; }<BR><BR>&nbsp;&nbsp;&nbsp; // Fields<BR>&nbsp;&nbsp;&nbsp; private String firstName;<BR>&nbsp;&nbsp;&nbsp; public String getFirstName() {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return firstName;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; public void setFirstName(String _firstName) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.firstName = _firstName;<BR>&nbsp;&nbsp;&nbsp; }<BR><BR>&nbsp;&nbsp;&nbsp; private java.util.Date birthDate;<BR>&nbsp;&nbsp;&nbsp; public java.util.Date getBirthDate() {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return birthDate;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; public void setBirthDate(java.util.Date _birthDate) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.birthDate = _birthDate;<BR>&nbsp;&nbsp;&nbsp; }<BR><BR>&nbsp;&nbsp;&nbsp; private String lastName;<BR>&nbsp;&nbsp;&nbsp; public String getLastName() {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return lastName;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; public void setLastName(String _lastName) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.lastName = _lastName;<BR>&nbsp;&nbsp;&nbsp; }<BR><BR>&nbsp;&nbsp;&nbsp; private long userId;<BR>&nbsp;&nbsp;&nbsp; public long getUserId() {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return userId;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; public void setUserId(long _userId) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.userId = _userId;<BR>&nbsp;&nbsp;&nbsp; }<BR>}<BR></FONT></P></TD></TR></TBODY></TABLE></P>
<P><FONT size=2>映射文件如下：<BR></FONT>
<TABLE style="WIDTH: 541px; HEIGHT: 954px" cellSpacing=1 cellPadding=1 width=541 border=1>
<TBODY>
<TR>
<TD><FONT size=2>&nbsp;</FONT><PRE><FONT size=2>&lt;?xml version='1.0'?&gt;

&lt;!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
    "http://www.ibatis.com/dtd/sql-map-2.dtd"&gt;


&lt;!-- WARNING: This is an autogenerated file --&gt;

&lt;sqlMap name="UserProperty"&gt;

    &lt;cacheModel id="userproperty-cache" type="MEMORY"&gt;
        &lt;flushInterval hours="24"/&gt;
        &lt;flushOnExecute statement="insertUserProperty"/&gt;
        &lt;flushOnExecute statement="updateUserProperty"/&gt;
        &lt;flushOnExecute statement="deleteUserProperty"/&gt;
        &lt;property name="reference-type" value="WEAK" /&gt;
    &lt;/cacheModel&gt;

    &lt;resultMap class="org.mystuff.db.UserProperty" id="userproperty-result" &gt;
        &lt;result property="firstName" column="FIRST_NAME" /&gt;
        &lt;result property="birthDate" column="BIRTH_DATE" /&gt;
        &lt;result property="lastName" column="LAST_NAME" /&gt;
        &lt;result property="userId" column="USER_ID" /&gt;
    &lt;/resultMap&gt;

    &lt;select id="getUserProperty" resultClass="org.mystuff.db.UserProperty" </FONT></PRE><PRE><FONT size=2>parameterClass="org.mystuff.db.UserProperty" resultMap="userproperty-result" &gt;
        &lt;![CDATA[
            select * from USER_PROPERTY
            where  USER_ID = #userId#
        ]]&gt;
    &lt;/select&gt;

    &lt;update id="updateUserProperty" parameterClass="org.mystuff.db.UserProperty"&gt;
        &lt;![CDATA[
            update USER_PROPERTY
            set  FIRST_NAME = #firstName# ,  BIRTH_DATE = #birthDate# </FONT></PRE><PRE><FONT size=2>            ,  LAST_NAME = #lastName#
            where  USER_ID = #userId#
        ]]&gt;
    &lt;/update&gt;

    &lt;insert id="insertUserProperty" parameterClass="org.mystuff.db.UserProperty"&gt;
        &lt;![CDATA[
            insert into USER_PROPERTY(FIRST_NAME, BIRTH_DATE, LAST_NAME, USER_ID)
            values(#firstName#, #birthDate#, #lastName#, #userId#)
        ]]&gt;
    &lt;/insert&gt;

    &lt;delete id="deleteUserProperty" parameterClass="org.mystuff.db.UserProperty"&gt;
        &lt;![CDATA[
            delete  from USER_PROPERTY
            where  USER_ID = #userId#
        ]]&gt;
    &lt;/delete&gt;

&lt;/sqlMap&gt;</FONT></PRE></TD></TR></TBODY></TABLE></P>
<P><FONT size=2>&nbsp;&nbsp;&nbsp; Jasmine IDE iBATIS GUI（</FONT><A href="http://jasmineide.sourceforge.net/"><FONT size=2>http://jasmineide.sourceforge.net</FONT></A><FONT size=2>）。在构建映射文件、VO、DAO 类（不是 iBATIS 的 DAO，而是一个调用 sqlclient 方法的 java 类）方面这是最好的了，通过点击几下鼠标就可生成。这个工具允许你建立一个项目并设置 DB 连接连同所有通常用到的配置文件。（首先你需要设置自己的 DB 连接，确定你的驱动程序和所有 jar 都在系统类路径中）<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <IMG height=417 alt="" src="http://jasmineide.sourceforge.net/pics/DVPluginSmall.png" width=577><BR>&nbsp;&nbsp;&nbsp; </FONT></P>
<P><FONT size=2>&nbsp;&nbsp;&nbsp; 我想，随着时间的推移，会有更多的开发者加入为 iBATIS 添砖加瓦的行列。<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; <STRONG><FONT size=3>重要改进议题</FONT></STRONG><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; </FONT><A href="http://wiki.apache.org/ibatis/Improved_Dynamic_SQL_Whiteboard"><FONT size=2>http://wiki.apache.org/ibatis/Improved_Dynamic_SQL_Whiteboard</FONT></A><FONT size=2> 这里正在讨论关于改进动态 SQL 的白板，让 iBATIS Data Mapper 在动态 SQL 方面更强大。另外，当开发某个有着大量查询和大量数据的系统时，通常也会对这些数据的子集进行开发。“记录长时间运行的查询”功能将加快开发进度，能帮助开发者或 DBA 了解哪个查询慢或尚未优化，找出潜在瓶颈。为了引入这种新特性，也许会修改 sqlmap 配置文件（比如默认临界值），也会在 mapped statement 中增加新属性（用来覆盖默认临界值）。<BR><BR><BR><STRONG><FONT color=#ff0000>请注意！引用、转贴本文应注明原作者：Rosen Jiang 以及出处：</FONT></STRONG><A href="http://www.blogjava.net/rosen"><FONT face=宋体 color=#ff0000 size=2><STRONG>http://www.blogjava.net/rosen</STRONG></FONT></A></FONT></P><img src ="http://www.blogjava.net/rosen/aggbug/9938.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rosen/" target="_blank">Rosen</a> 2005-08-12 15:12 <a href="http://www.blogjava.net/rosen/archive/2005/08/12/9938.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Hibernate、iBATIS 与 BLOB</title><link>http://www.blogjava.net/rosen/archive/2005/08/12/9937.html</link><dc:creator>Rosen</dc:creator><author>Rosen</author><pubDate>Fri, 12 Aug 2005 07:06:00 GMT</pubDate><guid>http://www.blogjava.net/rosen/archive/2005/08/12/9937.html</guid><wfw:comment>http://www.blogjava.net/rosen/comments/9937.html</wfw:comment><comments>http://www.blogjava.net/rosen/archive/2005/08/12/9937.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.blogjava.net/rosen/comments/commentRss/9937.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rosen/services/trackbacks/9937.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 2007-04-16   版权声明																		我知道这篇文章阅读量很大，但是请要继续转载本文的同志注意一下，本文是我在 2005 年春节期间写的，春节是合家团圆的日子，所以在这个时候写点东西不容易，整整花了我将近 20 天的时间啊。请保留原文版权信息 OK？								-----------------------------------...&nbsp;&nbsp;<a href='http://www.blogjava.net/rosen/archive/2005/08/12/9937.html'>阅读全文</a><img src ="http://www.blogjava.net/rosen/aggbug/9937.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rosen/" target="_blank">Rosen</a> 2005-08-12 15:06 <a href="http://www.blogjava.net/rosen/archive/2005/08/12/9937.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>iBATIS SQL Maps（四）</title><link>http://www.blogjava.net/rosen/archive/2005/08/12/9936.html</link><dc:creator>Rosen</dc:creator><author>Rosen</author><pubDate>Fri, 12 Aug 2005 06:55:00 GMT</pubDate><guid>http://www.blogjava.net/rosen/archive/2005/08/12/9936.html</guid><wfw:comment>http://www.blogjava.net/rosen/comments/9936.html</wfw:comment><comments>http://www.blogjava.net/rosen/archive/2005/08/12/9936.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rosen/comments/commentRss/9936.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rosen/services/trackbacks/9936.html</trackback:ping><description><![CDATA[
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">这一章节是本系列文章最后一篇。经历过前三篇文章的洗礼，相信你对</span>
				<span style="FONT-FAMILY: Arial">
				</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">iBATIS SQL Maps </span>
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">有比较详细的认识了吧？</span>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">来看看新需求：</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">
						<p>
						</p>
				</span>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">张三后来做生意，自己经营得很好，打算再买辆车跑运输。对于第二次买车，车辆管理系统的</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial"> PEOPLE </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">表原本已经记录了他的基本信息，遂不对</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial"> PEOPLE </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">表操作。只向</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial"> AUTO_INFO</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">表</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial"> insert </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">一条车辆记录即可。</span>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">新需求所用到的技术要点都在《</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">
						<a href="http://blog.csdn.net/rosen/archive/2005/01/16/255437.aspx">iBATIS SQL Maps<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">（二）</span></a>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">》和《</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">
						<a href="http://blog.csdn.net/rosen/archive/2005/01/21/263047.aspx">iBATIS SQL Maps<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">（三）</span></a>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">》中出现过了。请看映射文件：</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">
				</span>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US">
						<p>
						</p>
						<table style="WIDTH: 524px; HEIGHT: 100px" height="100" cellspacing="0" cellpadding="0" width="524" border="1">
								<tbody>
										<tr>
												<td>
														<p>
																<font size="2">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</font>
														</p>
														<p>
																<font size="2">&lt;!DOCTYPE sqlMap<br />    PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"<br />    "</font>
																<a href="http://www.ibatis.com/dtd/sql-map-2.dtd">
																		<font size="2">http://www.ibatis.com/dtd/sql-map-2.dtd</font>
																</a>
																<font size="2">"&gt;</font>
														</p>
														<p>
																<font size="2">&lt;sqlMap&gt;</font>
														</p>
														<p>
																<font size="2">  &lt;insert id="insertAutoInfo" parameterClass="bo.AutoInfo"&gt;<br />    &lt;![CDATA[ <br />      insert into auto_info (license_plate, owner_no) values (#licensePlate#, #ownerNo.id#)<br />    ]]&gt;<br />  &lt;/insert&gt;</font>
														</p>
														<p>
																<font size="2">    &lt;resultMap id="get-autoInfo-result" class="bo.AutoInfo"&gt;<br />        &lt;result property="id" column="auto_id"/&gt;<br />        &lt;result property="licensePlate" column="license_plate"/&gt;<br />    &lt;/resultMap&gt;</font>
														</p>
														<p>
																<font size="2">    &lt;resultMap id="get-people-result" class="bo.People"&gt;<br />        &lt;result property="id" column="owner_id"/&gt;<br />        &lt;result property="name" column="name"/&gt;<br />        &lt;result property="address" column="address"/&gt;<br />        &lt;result property="autoInfoList" column="owner_id" select="getAutoInfo"/&gt;<br />    &lt;/resultMap&gt;</font>
														</p>
														<p>
																<font size="2">  &lt;select id="getPeople" resultMap="get-people-result" parameterClass="bo.People"&gt;<br />       &lt;![CDATA[ <br />       select * from people<br />       ]]&gt;<br />       &lt;dynamic prepend="where"&gt;<br />         &lt;isNotNull property="id"&gt;<br />           &lt;![CDATA[ <br />           owner_id=#id#<br />           ]]&gt;<br />         &lt;/isNotNull&gt;<br />       &lt;/dynamic&gt;<br />  &lt;/select&gt;</font>
														</p>
														<p>
																<font size="2">  &lt;select id="getAutoInfo" resultMap="get-autoInfo-result" parameterClass="int"&gt;<br />       &lt;![CDATA[ <br />       select * from auto_info where owner_no=#id#<br />        ]]&gt;<br />  &lt;/select&gt;<br />  <br />&lt;/sqlMap&gt;</font>
														</p>
												</td>
										</tr>
								</tbody>
						</table> </span> </p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">简单地组合一下以前出现过的映射文件，就能满足新需求。相应程序代码如下：</span>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US" style="FONT-FAMILY: Arial">
						<p>
						</p>
						<table style="WIDTH: 527px; HEIGHT: 100px" height="100" cellspacing="0" cellpadding="0" width="527" border="1">
								<tbody>
										<tr>
												<td>
														<p>
																<font size="2">package test;</font>
														</p>
														<p>
																<font size="2">import java.io.Reader;</font>
														</p>
														<p>
																<font size="2">import com.ibatis.sqlmap.client.*;<br />import com.ibatis.common.resources.*;</font>
														</p>
														<p>
																<font size="2">import bo.*;</font>
														</p>
														<p>
																<font size="2">public class AutoMag {</font>
														</p>
														<p>
																<font size="2"> private Reader reader;<br /> private SqlMapClient sqlMap;<br /> private String resource = "SqlMapConfig.xml";<br /> <br /> public void insertPeople() throws Exception{<br />  try{<br />       reader = Resources.getResourceAsReader(resource);<br />       sqlMap=SqlMapClientBuilder.buildSqlMapClient(reader);<br />       sqlMap.startTransaction();<br />      <br />       People people=new People();<br />       people.setId(new Integer("1"));<br />       people=(People)sqlMap.queryForObject("getPeople",people);</font>
														</p>
														<p>
																<font size="2">       AutoInfo autoInfo=new AutoInfo();<br />       autoInfo.setLicensePlate("A00002");<br />       autoInfo.setOwnerNo(people);<br />       sqlMap.insert("insertAutoInfo",autoInfo);<br />      <br />       sqlMap.commitTransaction();<br />  }finally{<br />       sqlMap.endTransaction();<br />  }<br /> }<br />}</font>
														</p>
												</td>
										</tr>
								</tbody>
						</table> </span> </p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">程序代码也是简单组合一下而已，想想</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial"> Hibernate </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">又是怎么写的呢？相信有</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial"> JDBC </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">经验的程序员应该更喜欢</span>
				<span style="FONT-FAMILY: Arial">
				</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">iBATIS SQL Maps </span>
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">！</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">
				</span>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0">
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">斗转星移、峰回路转，</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">张三在经历过生意红火之后，接下来的一年内生意场上连连告负，不得不把自己的摊子收缩一下。这第一件事要把跑运输的车卖掉，就是</span>
				<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">那辆牌照为</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">“</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">A00002”</span>
				<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">的</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">。</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">
				</span>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">相应映射文件只需小小修改：</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">
				</span>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US" style="FONT-FAMILY: Arial">
						<p>
						</p>
						<table style="WIDTH: 528px; HEIGHT: 100px" height="100" cellspacing="0" cellpadding="0" width="528" border="1">
								<tbody>
										<tr>
												<td>
														<p>
																<font size="2">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</font>
														</p>
														<p>
																<font size="2">&lt;!DOCTYPE sqlMap<br />    PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"<br />    "</font>
																<a href="http://www.ibatis.com/dtd/sql-map-2.dtd">
																		<font size="2">http://www.ibatis.com/dtd/sql-map-2.dtd</font>
																</a>
																<font size="2">"&gt;</font>
														</p>
														<p>
																<font size="2">&lt;sqlMap&gt;<br />  <br />  &lt;delete id="deleteAutoInfo" parameterClass="bo.AutoInfo"&gt;<br />    &lt;![CDATA[ <br />    delete from auto_info where license_plate=#licensePlate# and owner_no=#ownerNo.id#<br />    ]]&gt;<br />  &lt;/delete&gt;</font>
														</p>
														<p>
																<font size="2">    &lt;resultMap id="get-autoInfo-result" class="bo.AutoInfo"&gt;<br />        &lt;result property="id" column="auto_id"/&gt;<br />        &lt;result property="licensePlate" column="license_plate"/&gt;<br />    &lt;/resultMap&gt;</font>
														</p>
														<p>
																<font size="2">    &lt;resultMap id="get-people-result" class="bo.People"&gt;<br />        &lt;result property="id" column="owner_id"/&gt;<br />        &lt;result property="name" column="name"/&gt;<br />        &lt;result property="address" column="address"/&gt;<br />        &lt;result property="autoInfoList" column="owner_id" select="getAutoInfo"/&gt;<br />    &lt;/resultMap&gt;</font>
														</p>
														<p>
																<font size="2">  &lt;select id="getPeople" resultMap="get-people-result" parameterClass="bo.People"&gt;<br />       &lt;![CDATA[ <br />       select * from people<br />       ]]&gt;<br />       &lt;dynamic prepend="where"&gt;<br />         &lt;isNotNull property="id"&gt;<br />           &lt;![CDATA[ <br />           owner_id=#id#<br />           ]]&gt;<br />         &lt;/isNotNull&gt;<br />       &lt;/dynamic&gt;<br />  &lt;/select&gt;</font>
														</p>
														<p>
																<font size="2">  &lt;select id="getAutoInfo" resultMap="get-autoInfo-result" parameterClass="int"&gt;<br />       &lt;![CDATA[ <br />       select * from auto_info where owner_no=#id#<br />        ]]&gt;<br />  &lt;/select&gt;<br />  <br />&lt;/sqlMap&gt;</font>
														</p>
												</td>
										</tr>
								</tbody>
						</table>
				</span> </p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">添加了一个</span>
				<span style="FONT-FAMILY: Arial">
				</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">delete</span>
				<span lang="EN-US" style="COLOR: black; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">
				</span>
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类型的</span>
				<span style="COLOR: black; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">
				</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">Mapped Statement</span>
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">。同样，也无需再解释了。相应程序代码：</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">
				</span>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US" style="FONT-FAMILY: Arial">
						<p>
						</p>
						<table style="WIDTH: 525px; HEIGHT: 100px" height="100" cellspacing="0" cellpadding="0" width="525" border="1">
								<tbody>
										<tr>
												<td>
														<p>
																<font size="2">package test;</font>
														</p>
														<p>
																<font size="2">import java.io.Reader;</font>
														</p>
														<p>
																<font size="2">import com.ibatis.sqlmap.client.*;<br />import com.ibatis.common.resources.*;</font>
														</p>
														<p>
																<font size="2">import bo.*;</font>
														</p>
														<p>
																<font size="2">public class AutoMag {</font>
														</p>
														<p>
																<font size="2"> private Reader reader;<br /> private SqlMapClient sqlMap;<br /> private String resource = "SqlMapConfig.xml";<br /> <br /> public void delPeople() throws Exception{<br />  try{<br />      reader = Resources.getResourceAsReader(resource);<br />      sqlMap=SqlMapClientBuilder.buildSqlMapClient(reader);<br />      sqlMap.startTransaction();<br />      <br />      People people=new People();<br />      people.setId(new Integer("1"));<br />      people=(People)sqlMap.queryForObject("getPeople",people);</font>
														</p>
														<p>
																<font size="2">        AutoInfo autoInfo=new AutoInfo();<br />        autoInfo.setLicensePlate("A00002");<br />        autoInfo.setOwnerNo(people);            <br />      sqlMap.delete("deleteAutoInfo",autoInfo);<br />      <br />      sqlMap.commitTransaction();<br />  }finally{<br />      sqlMap.endTransaction();<br />  }<br /> }<br />}</font>
														</p>
												</td>
										</tr>
								</tbody>
						</table>
				</span>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">到这里，</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">iBATIS SQL Maps </span>
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">之旅也就结束了。是的，很有意犹未尽的感觉，还没按照</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt"> one-to-many </span>
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">方式删除张三和他所有的车辆呢。</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">
						<p>
						</p>
				</span>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0">
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">这个工作就留给你来完成吧！</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">
				</span>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US" style="FONT-FAMILY: Arial">
						<span style="mso-spacerun: yes">    </span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">我不想比较</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial"> Hibernate </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">和</span>
				<span style="FONT-FAMILY: Arial">
				</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">iBATIS SQL Maps </span>
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">孰优孰劣，因为这种比较实在无聊！从我开始写第一行</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt"> Delphi </span>
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">代码开始，就充斥着“</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">VC </span>
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">好？还是</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt"> Delphi </span>
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">好？”这样的比较！如果你尚未涉足过</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt"> JDBC</span>
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">，我想</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">Hibernate </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">会更适合你</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">… …<br /><br /><br /><strong><font face="宋体" color="#ff0000" size="2">请注意！引用、转贴本文应注明原作者：Rosen Jiang 以及出处：</font></strong><a href="/rosen"><font face="宋体" color="#ff0000" size="2"><strong>http://www.blogjava.net/rosen</strong></font></a></span>
		</p>
<img src ="http://www.blogjava.net/rosen/aggbug/9936.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rosen/" target="_blank">Rosen</a> 2005-08-12 14:55 <a href="http://www.blogjava.net/rosen/archive/2005/08/12/9936.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>iBATIS SQL Maps（三）</title><link>http://www.blogjava.net/rosen/archive/2005/08/12/9935.html</link><dc:creator>Rosen</dc:creator><author>Rosen</author><pubDate>Fri, 12 Aug 2005 06:35:00 GMT</pubDate><guid>http://www.blogjava.net/rosen/archive/2005/08/12/9935.html</guid><wfw:comment>http://www.blogjava.net/rosen/comments/9935.html</wfw:comment><comments>http://www.blogjava.net/rosen/archive/2005/08/12/9935.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rosen/comments/commentRss/9935.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rosen/services/trackbacks/9935.html</trackback:ping><description><![CDATA[
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">看看</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">iBATIS SQL Maps</span>
				<span lang="EN-US">
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是怎样从数据库按照</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">one-to-many </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">关系查询数据的：</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">
				</span>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US">
						<p>
						</p>
						<table style="WIDTH: 527px; HEIGHT: 456px" height="456" cellspacing="0" cellpadding="0" width="527" border="1">
								<tbody>
										<tr>
												<td>
														<p>
																<font size="2">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</font>
														</p>
														<p>
																<font size="2">&lt;!DOCTYPE sqlMap<br />    PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"<br />    "</font>
																<a href="http://www.ibatis.com/dtd/sql-map-2.dtd">
																		<font color="#000080" size="2">http://www.ibatis.com/dtd/sql-map-2.dtd</font>
																</a>
																<font size="2">"&gt;</font>
														</p>
														<p>
																<font size="2">&lt;sqlMap&gt;<br />    &lt;resultMap id="get-autoInfo-result" class="bo.AutoInfo"&gt;<br />        &lt;result property="id" column="auto_id"/&gt;<br />        &lt;result property="licensePlate" column="license_plate"/&gt;<br />    &lt;/resultMap&gt;</font>
														</p>
														<p>
																<font size="2">    &lt;resultMap id="get-people-result" class="bo.People"&gt;<br />        &lt;result property="id" column="owner_id"/&gt;<br />        &lt;result property="name" column="name"/&gt;<br />        &lt;result property="address" column="address"/&gt;<br />        &lt;result property="autoInfoList" column="owner_id" select="getAutoInfo"/&gt;<br />    &lt;/resultMap&gt;</font>
														</p>
														<p>
																<font size="2">  &lt;select id="getPeople" resultMap="get-people-result" parameterClass="bo.People"&gt;<br />       &lt;![CDATA[ <br />       select * from people where owner_id=#id#<br />        ]]&gt;<br />  &lt;/select&gt;</font>
														</p>
														<p>
																<font size="2">  &lt;select id="getAutoInfo" resultMap="get-autoInfo-result" parameterClass="int"&gt;<br />       &lt;![CDATA[ <br />       select * from auto_info where owner_no=#id#<br />        ]]&gt;<br />  &lt;/select&gt;<br />&lt;/sqlMap&gt;</font>
														</p>
												</td>
										</tr>
								</tbody>
						</table> <br /></span>
				<b style="mso-bidi-font-weight: normal">
						<span lang="EN-US" style="FONT-FAMILY: Arial">resultMap id="get-autoInfo-result" class="bo.AutoInfo"</span>
				</b>
				<span lang="EN-US" style="FONT-FAMILY: Arial">
				</span>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US" style="FONT-FAMILY: Arial">
						<span style="mso-spacerun: yes">    </span>resultMap </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">是</span>
				<span style="FONT-FAMILY: Arial">
						<span lang="EN-US">iBATIS SQL Maps </span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">框架中重要组件之一，</span>
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">你也许还记得</span>
				<span style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">
				</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">resultClass </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">吧？两者概念基本一致。</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">resultMap </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">则是可定制</span>
				<span style="FONT-FAMILY: Arial">
				</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">Mapped Statement </span>
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">返回对象的。可定制表现在：比如我有一张数据表包含</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">10</span>
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">个字段，但我的</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt"> POJO </span>
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">只定义了</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">5</span>
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">个属性，这时，只要取出我关心的字段就行。和</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt"> Hibernate </span>
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">类似，</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">resultMap </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">的</span>
				<span style="FONT-FAMILY: Arial">
						<b style="mso-bidi-font-weight: normal">
								<span lang="EN-US">result</span>
						</b>
						<span lang="EN-US">
						</span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">元素定义了</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial"> POJO </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">属性到数据表字段的映射。</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">
						<p>
						</p>
				</span>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">需要说明的是</span>
				<span style="FONT-FAMILY: Arial">
						<b style="mso-bidi-font-weight: normal">
								<span lang="EN-US">result</span>
						</b>
						<span lang="EN-US">
						</span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">元素</span>
				<span style="FONT-FAMILY: Arial">
						<b style="mso-bidi-font-weight: normal">
								<span lang="EN-US">select</span>
						</b>
				</span>
				<span lang="EN-US">
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">属性，该属性类似于加载了一个子查询，并自动载入，如果这个子查询包含多条结果，就自动把结果装载进</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">List</span>
				<span lang="EN-US">
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类型。该</span>
				<b style="mso-bidi-font-weight: normal">
						<span lang="EN-US" style="FONT-FAMILY: Arial">result</span>
				</b>
				<span lang="EN-US" style="FONT-FAMILY: Arial">
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">元素</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对应</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">People</span>
				<span lang="EN-US">
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中的属性为</span>
				<span lang="EN-US">”</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">autoInfoList”</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，而由</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">Hibernate</span>
				<span lang="EN-US">
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">生成的</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">People</span>
				<span lang="EN-US">
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">却是</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">Set</span>
				<span lang="EN-US">
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类型</span>
				<span lang="EN-US">”</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">autoInfoSet”</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，这两种类型无法直接互转，所以我修改了</span>
				<span lang="EN-US"> POJO </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">属性。</span>
				<span lang="EN-US">
				</span>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<b style="mso-bidi-font-weight: normal">
						<span lang="EN-US" style="FONT-FAMILY: Arial">select id="getPeople" resultMap="get-people-result" parameterClass="bo.People" 
<p></p></span>
				</b>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0">
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">此为</span>
				<span style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">
						<span lang="EN-US">select </span>
				</span>
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">类型</span>
				<span style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">
				</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">Mapped Statement</span>
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">。传入</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt"> People </span>
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">实例，返回为自己定制、包含</span>
				<span lang="EN-US">”</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">autoInfoList”</span>
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">的</span>
				<span style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">
						<span lang="EN-US">People </span>
				</span>
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">实例。传入</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">People </span>
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">类型参数是为了便于多字段匹配查询，今天也许我只需利用</span>
				<span style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">
						<span lang="EN-US">People.id </span>
				</span>
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">单字段匹配就能得到结果，但下次的新需求也许是</span>
				<span style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">
						<span lang="EN-US">People.address </span>
				</span>
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">和</span>
				<span style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">
						<span lang="EN-US">People.name </span>
				</span>
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">联合匹配！</span>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">相应程序代码：</span>
				<span lang="EN-US">
						<p>
						</p>
				</span>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0">
				<span lang="EN-US" style="FONT-FAMILY: Arial">
						<p>
						</p>
						<table style="WIDTH: 525px; HEIGHT: 386px" height="386" cellspacing="0" cellpadding="0" width="525" border="1">
								<tbody>
										<tr>
												<td>
														<p>
																<font size="2">package test;</font>
														</p>
														<p>
																<font size="2">import java.io.Reader;<br />import java.util.List;</font>
														</p>
														<p>
																<font size="2">import com.ibatis.sqlmap.client.*;<br />import com.ibatis.common.resources.*;</font>
														</p>
														<p>
																<font size="2">import bo.*;</font>
														</p>
														<p>
																<font size="2">public class AutoMag {</font>
														</p>
														<p>
																<font size="2"> private Reader reader;<br /> private People people=new People();<br /> private SqlMapClient sqlMap;<br /> private String resource = "SqlMapConfig.xml";<br /> <br /> public People findPeople() throws Exception{<br />  reader = Resources.getResourceAsReader(resource);<br />   sqlMap=SqlMapClientBuilder.buildSqlMapClient(reader);<br />  <br />   people.setId(new Integer("1"));<br />   <font color="#ff0000">people=(People)sqlMap.queryForObject("getPeople",people);</font><br />   return people;<br /> }<br />}</font>
														</p>
												</td>
										</tr>
								</tbody>
						</table> </span> </p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<b style="mso-bidi-font-weight: normal">
						<span lang="EN-US" style="FONT-FAMILY: Arial">sqlMap.queryForObject(String arg0, Object arg1) 
<p></p></span>
				</b>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0">
				<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">此方法类似</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt"> Hibernate </span>
				<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">的</span>
				<span style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">
						<span lang="EN-US">session.load(…)</span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">，传入</span>
				<span style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">
				</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">Mapped Statement id</span>
				<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">，再传入包含主键的对象实例。除我上面列举的</span>
				<span style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">
						<span lang="EN-US">sqlMap.</span>
				</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">queryForObject(String arg0, Object arg1) </span>
				<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">外，还有重载方法</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">：</span>
				<b style="mso-bidi-font-weight: normal">
						<span lang="EN-US" style="FONT-FAMILY: Arial">
						</span>
				</b>
		</p>
		<span lang="EN-US" style="FONT-FAMILY: Arial">
				<p>
				</p>
				<table style="WIDTH: 521px; HEIGHT: 69px" height="69" cellspacing="0" cellpadding="0" width="521" border="1">
						<tbody>
								<tr>
										<td>
												<p>
														<font color="#ff0000" size="2">people=(People)sqlMap.queryForObject("getPeople",people);</font>
												</p>
												<p>
														<font size="2">替换成</font>
												</p>
												<p>
														<font color="#ff0000" size="2">sqlMap.queryForObject("getPeople", people, people);</font>
												</p>
										</td>
								</tr>
						</tbody>
				</table> <br /></span>
		<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">第一个</span>
		<span lang="EN-US">”</span>
		<span lang="EN-US" style="FONT-FAMILY: Arial">people</span>
		<span lang="EN-US">”</span>
		<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是传入参数，第二个</span>
		<span lang="EN-US">”</span>
		<span lang="EN-US" style="FONT-FAMILY: Arial">people</span>
		<span lang="EN-US">”</span>
		<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是返回的结果。</span>
		<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">要表达的意思一样，只不过换了种表现形式</span>
		<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。</span>
		<span lang="EN-US">
		</span>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<b style="mso-bidi-font-weight: normal">
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">下面我会讲到如何以集合类持有多个</span>
				</b>
				<b style="mso-bidi-font-weight: normal">
						<span lang="EN-US" style="FONT-FAMILY: Arial"> People </span>
				</b>
				<b style="mso-bidi-font-weight: normal">
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">对象实例。</span>
				</b>
				<b style="mso-bidi-font-weight: normal">
						<span lang="EN-US" style="FONT-FAMILY: Arial">
						</span>
				</b>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">在车辆管理应用中，需要把人员一一列出，选中某个再显示详细内容。类似于这样的需求，</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">iBATIS SQL Maps </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">引入</span>
				<span style="FONT-FAMILY: Arial">
						<span lang="EN-US">sqlMap.queryForList(String arg0, Object arg1) </span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">来满足。</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">
						<p>
						</p>
				</span>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US" style="FONT-FAMILY: Arial">
						<span style="mso-spacerun: yes">      </span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">还记得我们的映射文件怎么写的？对了，传入主键值再查询！</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">
						<p>
						</p>
				</span>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">但是，新需求不要任何条件，直接列出人员啊！难道还要再添加新的</span>
				<span style="FONT-FAMILY: Arial">
				</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">Mapped Statement </span>
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">来满足？动态</span>
				<span style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">
						<span lang="EN-US">Mapped Statement </span>
				</span>
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">能满足在不改变映射文件的前提下提供有参数和无差数查询：</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">
				</span>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US" style="FONT-FAMILY: Arial">
						<p>
						</p>
						<table style="WIDTH: 528px; HEIGHT: 597px" height="597" cellspacing="0" cellpadding="0" width="528" border="1">
								<tbody>
										<tr>
												<td>
														<p>
																<font size="2">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</font>
														</p>
														<p>
																<font size="2">&lt;!DOCTYPE sqlMap<br />    PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"<br />    "</font>
																<a href="http://www.ibatis.com/dtd/sql-map-2.dtd">
																		<font color="#000080" size="2">http://www.ibatis.com/dtd/sql-map-2.dtd</font>
																</a>
																<font size="2">"&gt;</font>
														</p>
														<p>
																<font size="2">&lt;sqlMap&gt;<br />    &lt;resultMap id="get-autoInfo-result" class="bo.AutoInfo"&gt;<br />        &lt;result property="id" column="auto_id"/&gt;<br />        &lt;result property="licensePlate" column="license_plate"/&gt;<br />    &lt;/resultMap&gt;</font>
														</p>
														<p>
																<font size="2">    &lt;resultMap id="get-people-result" class="bo.People"&gt;<br />        &lt;result property="id" column="owner_id"/&gt;<br />        &lt;result property="name" column="name"/&gt;<br />        &lt;result property="address" column="address"/&gt;<br />        &lt;result property="autoInfoList" column="owner_id" select="getAutoInfo"/&gt;<br />    &lt;/resultMap&gt;</font>
														</p>
														<p>
																<font size="2">  &lt;select id="getPeople" resultMap="get-people-result" parameterClass="bo.People"&gt;<br />       &lt;![CDATA[ <br />       select * from people<br />       ]]&gt;<br />       &lt;dynamic prepend="where"&gt;<br />         &lt;isNotNull property="id"&gt;<br />           &lt;![CDATA[ <br />           owner_id=#id#<br />           ]]&gt;<br />         &lt;/isNotNull&gt;<br />       &lt;/dynamic&gt;<br />  &lt;/select&gt;</font>
														</p>
														<p>
																<font size="2">  &lt;select id="getAutoInfo" resultMap="get-autoInfo-result" parameterClass="int"<br />                    resultClass="bo.AutoInfo"&gt;<br />       &lt;![CDATA[ <br />       select * from auto_info where owner_no=#id#<br />        ]]&gt;<br />  &lt;/select&gt;<br />&lt;/sqlMap&gt;</font>
														</p>
												</td>
										</tr>
								</tbody>
						</table>
				</span> </p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<b style="mso-bidi-font-weight: normal">
						<span lang="EN-US" style="FONT-FAMILY: Arial">dynamic prepend="where" 
<p></p></span>
				</b>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0">
				<span lang="EN-US" style="FONT-FAMILY: Arial">select</span>
				<span lang="EN-US">
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类型</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">Mapped Statement </span>
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">的本质并无改变，只是通过</span>
				<span style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">
				</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">dynamic </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">元素定义了动态</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial"> where </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">子句。</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">dynamic </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">元素属性</span>
				<span style="FONT-FAMILY: Arial">
						<span lang="EN-US">prepend=”where”</span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">在一元判定元素</span>
				<span style="FONT-FAMILY: Arial">
						<span lang="EN-US">isNotNull </span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">返回</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">”true”</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">时有效。</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">isNotNull </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">元素属性</span>
				<span style="FONT-FAMILY: Arial">
						<span lang="EN-US">property="id" </span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">用于判定</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial"> People.id </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">是否为</span>
				<span style="FONT-FAMILY: Arial">
						<span lang="EN-US">null</span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">，假如未传入包含主键值的</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial"> People </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">实例，</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">dynamic </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">元素将会无效，反之则亦然，这样就达到了在不改变映射文件的前提下实现动态</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial"> SQL </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">的目的。关于一元判定元素和二元判定元素的详细资料请查阅官方文档，如能恰当利用这些判定元素，动态</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial"> SQL </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">将会更灵活。</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">
				</span>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">相应程序代码：</span>
				<span lang="EN-US">
						<p>
						</p>
				</span>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US" style="FONT-FAMILY: Arial">
						<p>
						</p>
						<table style="WIDTH: 528px; HEIGHT: 374px" height="374" cellspacing="0" cellpadding="0" width="528" border="1">
								<tbody>
										<tr>
												<td>
														<p>
																<font size="2">package test;</font>
														</p>
														<p>
																<font size="2">import java.io.Reader;<br />import java.util.List;</font>
														</p>
														<p>
																<font size="2">import com.ibatis.sqlmap.client.*;<br />import com.ibatis.common.resources.*;</font>
														</p>
														<p>
																<font size="2">import bo.*;</font>
														</p>
														<p>
																<font size="2">public class AutoMag {</font>
														</p>
														<p>
																<font size="2"> private Reader reader;<br /> private People people=new People();<br /> private SqlMapClient sqlMap;<br /> private String resource = "SqlMapConfig.xml";<br /> <br /> public List findPeople() throws Exception{<br />  reader = Resources.getResourceAsReader(resource);<br />  sqlMap=SqlMapClientBuilder.buildSqlMapClient(reader);<br />      <br />  <font color="#ff0000">List list=sqlMap.queryForList("getPeople",null);</font><br />  return list;<br /> }<br />}</font>
														</p>
												</td>
										</tr>
								</tbody>
						</table> </span>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">传入</span>
				<span style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">
				</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">Mapped Statement id</span>
				<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">，再传入未包含主键的对象实例，也可以干脆传</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt"> null </span>
				<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">进去。重载方法</span>
				<span style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">
				</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">sqlMap</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">.queryForList(String arg0, Object arg1,<code><span style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-ansi-font-size: 10.5pt"> int arg2, int arg3</span></code>) </span>
				<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">用于分页</span>
				<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">，</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">arg2</span>
				<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">、</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">arg3</span>
				<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">分别代表页码和每页个数。</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">
				</span>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">好了，使用动态</span>
				<span style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">
						<span lang="EN-US" style="COLOR: black">Mapped Statement</span>
				</span>
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">，再试试</span>
				<span style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">
				</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">queryForObject(String arg0, Object arg1) </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">吧！<br /><br /><br /><br /><strong><font color="#ff0000" size="2">请注意！引用、转贴本文应注明原作者：Rosen Jiang 以及出处：</font></strong><a href="/rosen"><font color="#ff0000" size="2"><strong>http://www.blogjava.net/rosen</strong></font></a></span>
		</p>
<img src ="http://www.blogjava.net/rosen/aggbug/9935.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rosen/" target="_blank">Rosen</a> 2005-08-12 14:35 <a href="http://www.blogjava.net/rosen/archive/2005/08/12/9935.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>iBATIS SQL Maps（二）</title><link>http://www.blogjava.net/rosen/archive/2005/08/12/9932.html</link><dc:creator>Rosen</dc:creator><author>Rosen</author><pubDate>Fri, 12 Aug 2005 06:10:00 GMT</pubDate><guid>http://www.blogjava.net/rosen/archive/2005/08/12/9932.html</guid><wfw:comment>http://www.blogjava.net/rosen/comments/9932.html</wfw:comment><comments>http://www.blogjava.net/rosen/archive/2005/08/12/9932.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rosen/comments/commentRss/9932.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rosen/services/trackbacks/9932.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 让我们重回到车辆管理系统和张三的故事中。				 										    																																		    								在												iBATIS SQL Maps 				的世界里也存在				 one-to-many				、				many-to-...&nbsp;&nbsp;<a href='http://www.blogjava.net/rosen/archive/2005/08/12/9932.html'>阅读全文</a><img src ="http://www.blogjava.net/rosen/aggbug/9932.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rosen/" target="_blank">Rosen</a> 2005-08-12 14:10 <a href="http://www.blogjava.net/rosen/archive/2005/08/12/9932.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>iBATIS SQL Maps（一）</title><link>http://www.blogjava.net/rosen/archive/2005/08/12/9931.html</link><dc:creator>Rosen</dc:creator><author>Rosen</author><pubDate>Fri, 12 Aug 2005 06:03:00 GMT</pubDate><guid>http://www.blogjava.net/rosen/archive/2005/08/12/9931.html</guid><wfw:comment>http://www.blogjava.net/rosen/comments/9931.html</wfw:comment><comments>http://www.blogjava.net/rosen/archive/2005/08/12/9931.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rosen/comments/commentRss/9931.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rosen/services/trackbacks/9931.html</trackback:ping><description><![CDATA[
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0">
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">前段时间写了些</span>
				<span style="FONT-FAMILY: Arial">
						<span lang="EN-US">Hibernate </span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">方面的</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">
						<a href="/rosen/archive/2005/08/12/9910.html">
								<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">
										<font color="#000080">系列文章</font>
								</span>
						</a>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">，网友们反映还不错。在接下来的时间里，我将会引入另外一种</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">O/R Mapping </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">解决方案</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">——<b style="mso-bidi-font-weight: normal">iBATIS</b></span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">，本系列将沿用</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">Hibernate </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">系列文章的风格。</span>
				<br />
				<b style="mso-bidi-font-weight: normal">
						<span style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">
								<br />什么是</span>
				</b>
				<b style="mso-bidi-font-weight: normal">
						<span style="FONT-SIZE: 14pt; FONT-FAMILY: Arial">
								<span lang="EN-US">
										<a href="http://www.ibatis.com/">
												<font color="#000080">iBATIS</font>
										</a>
								</span>
						</span>
				</b>
				<b style="mso-bidi-font-weight: normal">
						<span style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">？</span> <br /></b>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.5pt">
						<br />    和众多的</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">SourceForge </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.5pt">开源项目一样，</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">iBATIS </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.5pt">曾经也是其中的一员。在</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">2004</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.5pt">年</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">11</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.5pt">月</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">3</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.5pt">日成功地成为了</span>
				<span style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">
						<span lang="EN-US">
								<a href="http://incubator.apache.org/projects/ibatis.html">
										<font color="#000080">Apache Incubator</font>
								</a>
								<span style="COLOR: black">
								</span>
						</span>
				</span>
				<span style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-bidi-font-size: 10.5pt">下的子项目。</span>
				<span style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">
				</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">iBATIS </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">包括</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">for Java </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">和</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">for .NET </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">两个版本，</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">for Java </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">版提供了</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">SQL Maps </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">和</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">DAO </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">框架，</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">for .NET </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">只提供了</span>
				<span style="FONT-FAMILY: Arial">
						<span lang="EN-US">SQL Maps </span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">框架。从现在开始我们只对</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">for Java </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">版的</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">SQL Maps </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">展开讨论。</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">
				</span>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0">
				<span lang="EN-US" style="FONT-FAMILY: Arial">
						<p>
						</p>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">    你可以在</span>
				<span style="FONT-FAMILY: Arial">
						<span lang="EN-US">
								<a href="http://www.ibatis.com/">
										<font color="#000080">http://www.ibatis.com</font>
								</a>
						</span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">下载</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">iBATIS for Java</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">，目前最新版本是</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">2.0.9</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">，压缩包里已经包含了</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">SQL Maps(ibatis-sqlmap-2.jar) </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">和</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">DAO </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">框架</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">(ibatis-dao-2.jar)</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">。</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">
						<br />
				</span>
				<br />
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<b style="mso-bidi-font-weight: normal">
						<span style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">为什么选择</span>
				</b>
				<b style="mso-bidi-font-weight: normal">
						<span style="FONT-SIZE: 14pt; FONT-FAMILY: Arial">
								<span lang="EN-US">
										<a href="http://www.ibatis.com/">
												<font color="#000080">iBATIS</font>
										</a>
								</span>
						</span>
				</b>
				<b style="mso-bidi-font-weight: normal">
						<span style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">？</span>
				</b>
				<b style="mso-bidi-font-weight: normal">
						<span lang="EN-US" style="FONT-SIZE: 14pt; FONT-FAMILY: Arial"> <br /></span>
				</b>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">
						<br />    也许各位看官已在各种不同的技术资料上了解到它的优势。但是对于我来说，选择它的理由只有一个</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">——“</span>
				<b style="mso-bidi-font-weight: normal">
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">利用原有资源</span>
				</b>
				<span lang="EN-US" style="FONT-FAMILY: Arial">”</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">。</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">Hibernate </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">的却优秀，但是用来整合原有系统，它却很难胜任。例如，以前在进行数据建模时使用了复合主键、跨越多表产生的几十甚至上百行的查询语句、利用原有存储过程</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">… … </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">当面临这一系列问题时</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">Hibernate </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">就显得力不从心了，要想使用</span>
				<span lang="EN-US" style="FONT-FAMIL