﻿<?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-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>
		</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 </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">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">POJO</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="COLOR: red; FONT-FAMILY: Arial">BTW</span>
				</b>
				<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>
		</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">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">HQL</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>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> </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">O/R Mapping </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>
				<span lang="EN-US" style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">
						<p>
						</p>
				</span>
		</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 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">O/R Mapping </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">BO</span>
				</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">MySQL</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 style="COLOR: black">打开</span></span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">Eclipse</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 lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">Resin </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="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">
				</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">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">ibatis-common-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">lib </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">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">
						<span style="mso-spacerun: yes">    </span>
						<p>
						</p>
				</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>
				</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">src </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">SqlMapConfig.xml</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">SqlMap </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">这些都要靠它了。官方参考手册对怎样进行设置有很详细的描述，我只对要用到的地方进行粗略说明。<br /></span>
				<span lang="EN-US" style="FONT-FAMILY: Arial">
						<p>
						</p>
				</span>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<table style="WIDTH: 509px; HEIGHT: 100px" height="100" cellspacing="0" cellpadding="0" width="509" border="1">
				<tbody>
						<tr>
								<td>
										<p>
												<font size="2">&lt;?xml version="1.0" encoding="UTF-8" ?&gt;<br />&lt;!DOCTYPE sqlMapConfig<br />    PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"<br />    "</font>
												<a href="http://www.ibatis.com/dtd/sql-map-config-2.dtd">
														<font color="#000080" size="2">http://www.ibatis.com/dtd/sql-map-config-2.dtd</font>
												</a>
												<font size="2">"&gt;</font>
										</p>
										<p>
												<font size="2">&lt;sqlMapConfig&gt;</font>
										</p>
										<p>
												<font size="2">  &lt;settings<br />    cacheModelsEnabled="true"<br />    enhancementEnabled="true"<br />    lazyLoadingEnabled="true"<br />    errorTracingEnabled="false"<br />    maxRequests="32"<br />    maxSessions="10"<br />    maxTransactions="5"<br />    useStatementNamespaces="false"<br />    /&gt;</font>
										</p>
										<p>
												<font size="2">  &lt;transactionManager type="JDBC"&gt;<br />    &lt;dataSource type="SIMPLE"&gt;<br />      &lt;property name="JDBC.Driver" value="org.gjt.mm.mysql.Driver"/&gt;<br />      &lt;property name="JDBC.ConnectionURL" value="jdbc:mysql://localhost/new_db?useUnicode=true"/&gt;<br />      &lt;property name="JDBC.Username" value="root"/&gt;<br />      &lt;property name="JDBC.Password" value=""/&gt;<br />      &lt;property name="JDBC.DefaultAutoCommit" value="true"/&gt;<br />      &lt;property name="Pool.MaximumActiveConnections" value="10"/&gt;<br />      &lt;property name="Pool.MaximumIdleConnections" value="5"/&gt;<br />      &lt;property name="Pool.MaximumCheckoutTime" value="120000"/&gt;<br />      &lt;property name="Pool.TimeToWait" value="500"/&gt;<br />      &lt;property name="Pool.PingQuery" value="select 1 from ACCOUNT"/&gt;<br />      &lt;property name="Pool.PingEnabled" value="false"/&gt;<br />      &lt;property name="Pool.PingConnectionsOlderThan" value="1"/&gt;<br />      &lt;property name="Pool.PingConnectionsNotUsedFor" value="1"/&gt;<br />      &lt;property name="Pool.QuietMode" value="true"/&gt;<br />    &lt;/dataSource&gt;<br />  &lt;/transactionManager&gt;</font>
										</p>
										<p>
												<font size="2">  &lt;sqlMap resource="bo/mapping/AutoMag.xml"/&gt;<br />&lt;/sqlMapConfig&gt;</font>
										</p>
								</td>
						</tr>
				</tbody>
		</table>
		<b style="mso-bidi-font-weight: normal">
				<span lang="EN-US" style="FONT-SIZE: 12pt; FONT-FAMILY: Arial">
						<br />transactionManager </span>
		</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">元素定义了</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">type </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">
		</span>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21.1pt; TEXT-ALIGN: left; mso-char-indent-count: 2.0; mso-layout-grid-align: none" align="left">
				<b style="mso-bidi-font-weight: normal">
						<span lang="EN-US" style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">JDBC</span>
				</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; mso-font-kerning: 0pt">：通过传统</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">JDBC </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; mso-font-kerning: 0pt">来管理事务。</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">
						<p>
						</p>
				</span>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21.1pt; TEXT-ALIGN: left; mso-char-indent-count: 2.0; mso-layout-grid-align: none" align="left">
				<b style="mso-bidi-font-weight: normal">
						<span lang="EN-US" style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">JTA</span>
				</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; mso-font-kerning: 0pt">：使用一个</span>
				<span style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">
						<span lang="EN-US">JTA </span>
				</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; mso-font-kerning: 0pt">全局事务，使</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; mso-bidi-font-size: 10.5pt">iBATIS</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">
				</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; mso-font-kerning: 0pt">的事务包括在更大的事务范围内（跨数据库</span>
				<span lang="EN-US" style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">Session</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; mso-font-kerning: 0pt">的），这个更大的事务范围可能包括了其他的数据库和事务资源。这个配置需要一个</span>
				<span style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">
						<span lang="EN-US">UserTransaction </span>
				</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; mso-font-kerning: 0pt">属性，以便从</span>
				<span style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">
						<span lang="EN-US">JNDI </span>
				</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; mso-font-kerning: 0pt">获得一个</span>
				<span style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">
						<span lang="EN-US">UserTransaction</span>
				</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; mso-font-kerning: 0pt">。</span>
				<span style="FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">
						<span lang="EN-US">
								<span style="mso-spacerun: yes"> </span>
						</span>
				</span>
		</p>
		<p class="a" style="TEXT-JUSTIFY: inter-ideograph; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 20.65pt; TEXT-ALIGN: justify; mso-char-indent-count: 1.96">
				<b style="mso-bidi-font-weight: normal">
						<span lang="EN-US" style="FONT-SIZE: 10.5pt; FONT-FAMILY: Arial">EXTERNAL</span>
				</b>
				<span style="FONT-SIZE: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">
						<font face="宋体">：调用</font>
				</span>
				<span style="FONT-SIZE: 10.5pt; FONT-FAMILY: Arial">
						<span lang="EN-US">iBATIS </span>
				</span>
				<font face="宋体">
						<span style="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-SIZE: 10.5pt; FONT-FAMILY: Arial">
								<p>
								</p>
						</span>
				</font>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p class="Default" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US" style="FONT-SIZE: 10.5pt; FONT-FAMILY: Arial">
						<p>
						</p>
				</span>
				<b style="mso-bidi-font-weight: normal">
						<span lang="EN-US" style="FONT-SIZE: 12pt; COLOR: black; FONT-FAMILY: Arial">dataSource </span>
				</b>
				<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 lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">transactionManager </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 lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">type </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">可选项包括：<br /></span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt">
						<span style="mso-spacerun: yes">
								<br />    </span>
				</span>
				<b>
						<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">SIMPLE</span>
				</b>
				<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; mso-font-kerning: 0pt">：</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">SIMPLE </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; mso-font-kerning: 0pt">是</span>
				<span style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">
						<span lang="EN-US">iBATIS </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; mso-font-kerning: 0pt">内置的</span>
				<span style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">
						<span lang="EN-US">dataSource </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; mso-font-kerning: 0pt">实现，其中实现了一个简单的数据库连接池，当无容器提供</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">DataSource </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; mso-font-kerning: 0pt">服务时可以使用该选项，对应</span>
				<span style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">
						<span lang="EN-US">iBATIS </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; mso-font-kerning: 0pt">实现类为</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">com.ibatis.sqlmap.engine.datasource.SimpleDataSourceFactory</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; mso-font-kerning: 0pt">。</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">
				</span>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 5.25pt; TEXT-INDENT: -5.25pt; TEXT-ALIGN: left; mso-char-indent-count: -.5; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt"><span style="mso-spacerun: yes">    </span><b>DBCP:</b></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; mso-font-kerning: 0pt">基于</span>
				<span style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">
						<span lang="EN-US">Apache DBCP </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; mso-font-kerning: 0pt">连接池</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">API </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; mso-font-kerning: 0pt">实现的</span>
				<span style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">
						<span lang="EN-US">DataSource</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; mso-font-kerning: 0pt">，当无容器提供</span>
				<span style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">
						<span lang="EN-US">DataSource </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; mso-font-kerning: 0pt">服务时，可以使用该选项，对应</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">iBATIS </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; mso-font-kerning: 0pt">实现类为</span>
				<span style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">
						<span lang="EN-US">com.ibatis.sqlmap.engine.datasource.DbcpDataSourceFactory</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; mso-font-kerning: 0pt">。</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">
						<p>
						</p>
				</span>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-char-indent-count: 2.0; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt"><b style="mso-bidi-font-weight: normal">JNDI</b></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; mso-font-kerning: 0pt">：使用</span>
				<span style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">
						<span lang="EN-US">J2EE </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; mso-font-kerning: 0pt">容器提供的</span>
				<span style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">
						<span lang="EN-US">DataSource </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; mso-font-kerning: 0pt">实现，</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">DataSource </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; mso-font-kerning: 0pt">将通过指定的</span>
				<span style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">
						<span lang="EN-US">JNDI Name </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; mso-font-kerning: 0pt">从容器中获取。对应</span>
				<span style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">
						<span lang="EN-US">iBATIS </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; mso-font-kerning: 0pt">实现类为</span>
				<span style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">
						<span lang="EN-US">com.ibatis.sqlmap.engine.datasource.JndiDataSourceFactory</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; mso-font-kerning: 0pt">。</span>
				<span lang="EN-US" style="COLOR: black; FONT-FAMILY: Arial; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">
						<p>
						</p>
				</span>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p class="Default" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US" style="FONT-SIZE: 10.5pt; FONT-FAMILY: Arial">
						<span style="mso-spacerun: yes">   </span>
						<b style="mso-bidi-font-weight: normal">
								<span style="mso-spacerun: yes"> </span>
						</b>
				</span>
				<font face="宋体">
						<b style="mso-bidi-font-weight: normal">
								<span style="FONT-SIZE: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">注意！</span>
						</b>
						<span style="FONT-SIZE: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">每种</span>
				</font>
				<b style="mso-bidi-font-weight: normal">
						<span style="FONT-SIZE: 10.5pt; FONT-FAMILY: Arial">
						</span>
				</b>
				<span lang="EN-US" style="FONT-SIZE: 10.5pt; FONT-FAMILY: Arial">dataSource </span>
				<span style="FONT-SIZE: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">
						<font face="宋体">元素的</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10.5pt; FONT-FAMILY: Arial">property </span>
				<span style="FONT-SIZE: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">
						<font face="宋体">都有不同的地方，不能光把</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10.5pt; FONT-FAMILY: Arial">type </span>
				<font face="宋体">
						<span style="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-SIZE: 10.5pt; FONT-FAMILY: Arial">
								<p>
								</p>
						</span>
				</font>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p class="Default" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US" style="FONT-SIZE: 10.5pt; FONT-FAMILY: Arial">
						<p>
						</p>
				</span>
				<b style="mso-bidi-font-weight: normal">
						<span lang="EN-US" style="FONT-FAMILY: Arial">sqlMap </span>
				</b>
				<span style="FONT-SIZE: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">
						<font face="宋体">元素定义了映射文件的存放位置，配置文件中可包含多个</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10.5pt; FONT-FAMILY: Arial">sqlMap </span>
				<span style="FONT-SIZE: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">
						<font face="宋体">元素，比如：</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10.5pt; FONT-FAMILY: Arial">
				</span>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<table style="WIDTH: 514px; HEIGHT: 84px" height="84" cellspacing="0" cellpadding="0" width="514" border="1">
				<tbody>
						<tr>
								<td>
										<p>
												<font size="2">&lt;sqlMap resource="mapping/AutoMag1.xml"/&gt;<br />&lt;sqlMap resource="bo/mapping/AutoMag2.xml"/&gt;</font>
										</p>
										<p>
												<font size="2">&lt;sqlMap url="</font>
												<a href="file:///c:/eclipse/workspace/iBATISTest/src/bo/">
														<font color="#000080" size="2">file:///c:/eclipse/workspace/iBATISTest/src/bo/</font>
												</a>
												<font size="2">AutoMag2.xml "/&gt;<br />… …</font>
										</p>
								</td>
						</tr>
				</tbody>
		</table>
		<p class="Default" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0">
				<span style="FONT-SIZE: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">
						<font face="宋体">你也许已发现，我只定义了单个映射文件。不错，和</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10.5pt; FONT-FAMILY: Arial">Hibernate </span>
				<span style="FONT-SIZE: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">
						<font face="宋体">的一个表一个映射文件不同，</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10.5pt; FONT-FAMILY: Arial">iBATIS </span>
				<font face="宋体">
						<span style="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-SIZE: 10.5pt; FONT-FAMILY: Arial">
								<p>
								</p>
						</span>
				</font>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p class="Default" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US" style="FONT-SIZE: 10.5pt; FONT-FAMILY: Arial">
						<p>
						</p>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10.5pt; FONT-FAMILY: Arial">
						<span style="mso-spacerun: yes">    </span>
				</span>
				<span style="FONT-SIZE: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">
						<font face="宋体">光有</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10.5pt; FONT-FAMILY: Arial">BO </span>
				<span style="FONT-SIZE: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">
						<font face="宋体">和配置文件还不行，还要为本次测试创建测试类</font>
				</span>
				<span style="FONT-SIZE: 10.5pt; FONT-FAMILY: Arial">
						<span lang="EN-US">AutoMag.java</span>
				</span>
				<span style="FONT-SIZE: 10.5pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">
						<font face="宋体">。完整的布局如下所示：<br /></font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10.5pt; FONT-FAMILY: Arial">
						<br />                                        <img alt="" hspace="0" src="http://blog.csdn.net/images/blog_csdn_net/rosen/68948/r_structure.jpg" align="baseline" border="0" /><br /></span>
		</p>
		<p>
		</p>
		<p class="Default" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0">
				<span style="FONT-SIZE: 10.5pt">
						<font face="宋体">
								<br />    以下为<span lang="EN-US"> iBATIS SQL Maps 工作流程，对于理解概念很有帮助。大意是 1、你可以把 JavaBean、Map 类型、原始变量（或者它们的Wrapper Class）、XML 数据作为传入对象；2、通过配置文件载入映射文件；3、利用框架翻译成 JDBC 来访问数据库；4、执行结果可以是 JavaBean、Map 类型、原始变量的 Wrapper Class、XML 数据。<br /></span></font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10.5pt; FONT-FAMILY: Arial">
						<p>                              <img alt="" hspace="0" src="http://blog.csdn.net/images/blog_csdn_net/rosen/68948/r_map.jpg" align="baseline" border="0" /><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></p>
				</span>
		</p>
		<p>
		</p>
<img src ="http://www.blogjava.net/rosen/aggbug/9931.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:03 <a href="http://www.blogjava.net/rosen/archive/2005/08/12/9931.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>《我的 O/R Mapping 之旅》勘误及补充</title><link>http://www.blogjava.net/rosen/archive/2005/08/12/9916.html</link><dc:creator>Rosen</dc:creator><author>Rosen</author><pubDate>Fri, 12 Aug 2005 03:41:00 GMT</pubDate><guid>http://www.blogjava.net/rosen/archive/2005/08/12/9916.html</guid><wfw:comment>http://www.blogjava.net/rosen/comments/9916.html</wfw:comment><comments>http://www.blogjava.net/rosen/archive/2005/08/12/9916.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rosen/comments/commentRss/9916.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rosen/services/trackbacks/9916.html</trackback:ping><description><![CDATA[<A href="http://www.blogjava.net/rosen/archive/2005/08/12/9911.html"><FONT color=#000080>《我的 O/R Mapping 之旅(二)》</FONT></A>，有一段对 People.hbm.xml 的分析，谈到为什么使用 inverse=”true”：<BR><BR>
<TABLE style="WIDTH: 528px; HEIGHT: 93px" height=93 cellSpacing=0 cellPadding=0 width=528 border=1>
<TBODY>
<TR>
<TD><FONT size=2>在车辆管理系统中，代表着一个拥有者拥有多台车辆。以 java.util.Set 类型表示。 inverse 用于标识双向关联中的被动方一端。inverse=false 的一方（主控方）负责维护关联关系；<STRONG><FONT color=#ff0000>在车辆管理系统中， AutoInfo 作为主控方，应该把它设为“true”。</FONT></STRONG>这就好比你（被动方 one）在某个聚会上散发了许多名片，但是有可能你不清楚接收者（主动方 many）的具体背景；这个不要紧，接收者在必要的时候会和你联系就是了（主动维护关系）。</FONT></TD></TR></TBODY></TABLE><BR>红色标识的句子容易让人产生歧异，好像是在说把 AtuoInfo 设置成“true”了。应改为：<BR><BR>
<TABLE style="WIDTH: 528px; HEIGHT: 31px" height=31 cellSpacing=0 cellPadding=0 width=528 border=1>
<TBODY>
<TR>
<TD><FONT size=2>在车辆管理系统中，AtuoInfo 作为主控方，应该在 People 中设置 inverse =“true”。</FONT></TD></TR></TBODY></TABLE><BR>沿着思路往下走，你也许会问：什么才叫“主动维护关系”？不妨看看下面的代码（摘自<A href="http://www.blogjava.net/rosen/archive/2005/08/12/9914.html"><FONT color=#000080>《我的 O/R Mapping 之旅(三)》</FONT></A>）：<BR><BR>
<TABLE style="WIDTH: 526px; HEIGHT: 100px" height=100 cellSpacing=0 cellPadding=0 width=526 border=1>
<TBODY>
<TR>
<TD><FONT size=2>AutoInfo ai=new AutoInfo();<BR>People people=new People();<BR>public void DoTest() {<BR>&nbsp;&nbsp; try {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Configuration cfg = new Configuration().configure();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SessionFactory sessions = cfg.buildSessionFactory();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Session session = sessions.openSession();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Transaction tx = session.beginTransaction();<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ai.setLicensePlate("A00001");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT color=#ff0000><STRONG>ai.setOwnerNo(people);</STRONG></FONT><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;people.setAddress("中国");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;people.setName("张三");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;people.addToAutoInfoSet(ai);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;session.save(people);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tx.commit();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;session.close();<BR>&nbsp;&nbsp; } catch (Exception e) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(e);<BR>&nbsp;&nbsp; }<BR>}</FONT></TD></TR></TBODY></TABLE>
<P><BR>把“ai.setOwnerNo(people)”注解了试试，由于 AutoInfo 没有主动维护关系，导致 AUTO_INFO 表中 OWNER_NO 字段为“Null”。自然 AutoInfo 与 Poople 就不存在任何联系了。</P>
<P>人类的求知欲很强烈！<BR>为什么非要用 AutoInfo 作为主控方？People 作主控方不行？好吧，为 People.hbm.xml 删除inverse=”true”，再运行以上程序，其实也能保存，只是多了一条SQL：“update auto_info set OWNER_NO=? where AUTO_ID=?”，这就是 AutoInfo 被动地修改和 People 的联系。多执行一次 SQL 意味着多了一些开销，这是对性能不利的！</P>
<P><BR><A href="http://www.blogjava.net/rosen/archive/2005/08/12/9914.html"><FONT color=#000080>《我的 O/R Mapping 之旅(三)》</FONT></A>，有一段对张三第二次买车的程序和描述：<BR><BR>
<TABLE style="WIDTH: 523px; HEIGHT: 100px" height=100 cellSpacing=0 cellPadding=0 width=523 border=1>
<TBODY>
<TR>
<TD><FONT size=2>&nbsp;AutoInfo ai = new AutoInfo();<BR>&nbsp;People people = new People();<BR>&nbsp;public void DoTest() {<BR>&nbsp;&nbsp;try {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Configuration cfg = new Configuration().configure();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SessionFactory sessions = cfg.buildSessionFactory();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Session session = sessions.openSession();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Transaction tx = session.beginTransaction();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; people =<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (People) session<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .find(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "from People where OWNER_ID=1")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .get(0);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ai.setLicensePlate("A00002");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ai.setOwnerNo(people);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; people.getAutoInfoSet().add(ai);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <STRONG><FONT color=#ff0000>session.save(people);</FONT></STRONG><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tx.commit();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; session.close();<BR>&nbsp;&nbsp;} catch (Exception e) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(e);<BR>&nbsp;&nbsp;}<BR>}</FONT></TD></TR></TBODY></TABLE></P><BR>
<TABLE style="WIDTH: 523px; HEIGHT: 79px" height=79 cellSpacing=0 cellPadding=0 width=523 border=1>
<TBODY>
<TR>
<TD><FONT size=2>到这里，也许你会有这样的想法：“应该可以直接向 AUTO_INFO 表插入记录，不通过 People 对象中转，像写 SQL 一样 Easy。” 错了！以前直接写 SQL 是可以办到的，不过现在我们用的可是 Hibernate ，一切都要以对象行事，看见 ai.setOwnerNo(people) 了吗？传入参数是个 People 对象实例，不是简单的字段喔。</FONT></TD></TR></TBODY></TABLE><BR>这段解释太绝对了，事实上可以直接保存 AutoInfo 对象，而不用通过保存 People 来中转：<BR><BR>
<TABLE style="WIDTH: 522px; HEIGHT: 100px" height=100 cellSpacing=0 cellPadding=0 width=522 border=1>
<TBODY>
<TR>
<TD><FONT size=2>AutoInfo ai = new AutoInfo();<BR>People people = new People();<BR>public void DoTest() {<BR>&nbsp;&nbsp;try {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Configuration cfg = new Configuration().configure();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SessionFactory sessions = cfg.buildSessionFactory();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Session session = sessions.openSession();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Transaction tx = session.beginTransaction();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; people =<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (People) session<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .find(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "from People where OWNER_ID=1")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .get(0);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ai.setLicensePlate("A00002");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ai.setOwnerNo(people);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT color=#ff0000><STRONG>session.save(ai);</STRONG></FONT><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tx.commit();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; session.close();<BR>&nbsp;&nbsp;} catch (Exception e) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(e);<BR>&nbsp;&nbsp;}<BR>}</FONT></TD></TR></TBODY></TABLE>
<P><BR><BR><A href="http://www.blogjava.net/rosen/archive/2005/08/12/9915.html"><FONT color=#000080>《我的 O/R Mapping 之旅(四)》</FONT></A>，删除 PEOPLE 表及其关联的 AUTO_INFO 表时，程序是没有错，不过有更简单的办法来删除：</P>
<P>
<TABLE style="WIDTH: 522px; HEIGHT: 100px" height=100 cellSpacing=0 cellPadding=0 width=522 border=1>
<TBODY>
<TR>
<TD><FONT size=2>&nbsp;&nbsp;try {<BR>&nbsp;&nbsp;&nbsp;Configuration cfg = new Configuration().configure();<BR>&nbsp;&nbsp;&nbsp;SessionFactory sessions = cfg.buildSessionFactory();<BR>&nbsp;&nbsp;&nbsp;Session session = sessions.openSession();<BR>&nbsp;&nbsp;&nbsp;Transaction tx = session.beginTransaction();<BR>&nbsp;&nbsp;&nbsp;session.delete("from People where OWNER_ID=1");<BR>&nbsp;&nbsp;&nbsp;tx.commit();<BR>&nbsp;&nbsp;&nbsp;session.close();<BR>&nbsp;&nbsp;} catch (Exception e) {<BR>&nbsp;&nbsp;&nbsp;System.out.println(e);<BR>&nbsp;&nbsp;}</FONT></TD></TR></TBODY></TABLE><BR>Hibernate 中，要完成一次操作，可以有多种实现方式，哪种最好，就要靠自己定夺了。<BR><BR><BR><BR><STRONG><FONT face=宋体 color=#ff0000 size=2>请注意！引用、转贴本文应注明原作者：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></P><img src ="http://www.blogjava.net/rosen/aggbug/9916.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 11:41 <a href="http://www.blogjava.net/rosen/archive/2005/08/12/9916.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>我的 O/R Mapping 之旅（四）</title><link>http://www.blogjava.net/rosen/archive/2005/08/12/9915.html</link><dc:creator>Rosen</dc:creator><author>Rosen</author><pubDate>Fri, 12 Aug 2005 03:38:00 GMT</pubDate><guid>http://www.blogjava.net/rosen/archive/2005/08/12/9915.html</guid><wfw:comment>http://www.blogjava.net/rosen/comments/9915.html</wfw:comment><comments>http://www.blogjava.net/rosen/archive/2005/08/12/9915.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rosen/comments/commentRss/9915.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rosen/services/trackbacks/9915.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: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">接第三部分内容，本章节就要简单多了。</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: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">市场是无情的，机遇和危机无处不在。张三在经历过生意红火之后，接下来的一年内生意场上连连告负，不得不把自己的摊子收缩一下。这第一件事要把跑运输的车卖掉，就是</span>
				<span style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">那辆牌照为“</span>
				<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体">A00002”的</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。<br /><br /><table style="WIDTH: 528px; HEIGHT: 438px" height="438" cellspacing="0" cellpadding="0" width="528" border="1"><tbody><tr><td><p><font size="2">package com.dao;</font></p><p><font size="2">import java.util.*;</font></p><p><font size="2">import net.sf.hibernate.*;<br />import net.sf.hibernate.cfg.*;</font></p><p><font size="2">import bo.*;</font></p><p><font size="2">public class Test {</font></p><p><font size="2"> AutoInfo ai;<br /> People people;<br /> public void DoTest() {<br />  try {<br />   Configuration cfg = new Configuration().configure();<br />   SessionFactory sessions = cfg.buildSessionFactory();<br />   Session session = sessions.openSession();<br />   Transaction tx = session.beginTransaction();<br />   ai =<br />    (AutoInfo) session.find(<br />     "from AutoInfo where LICENSE_PLATE='A00002'").get(<br />     0);<br />   people = ai.getOwnerNo();<br />   people.getAutoInfoSet().remove(ai);<br />   session.delete(ai);<br />   tx.commit();<br />   session.close();<br />  } catch (Exception e) {<br />   System.out.println(e);<br />  }<br /> }<br />}</font></p></td></tr></tbody></table></span>
		</p>
		<br />
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<b style="mso-bidi-font-weight: normal">
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">为什么要从</span>
						<span lang="EN-US">People </span>
				</b>
				<b style="mso-bidi-font-weight: normal">
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象中移除某个</span>
						<span lang="EN-US">AutoInfo </span>
				</b>
				<b style="mso-bidi-font-weight: normal">
						<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象？</span>
				</b>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<b style="mso-bidi-font-weight: normal">
						<span lang="EN-US">
								<span style="mso-spacerun: yes">    </span>
						</span>
				</b>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">问得好！传统</span>
				<span lang="EN-US"> JDBC </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">程序可以直接删除以“</span>
				<span lang="EN-US">A00002</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">”为条件查询出的记录，这样没有问题。但如果在</span>
				<span lang="EN-US"> Hibernate </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中用同样的方式直接删除，会引起不小的麻烦：<br /><br /><table style="WIDTH: 529px; HEIGHT: 36px" height="36" cellspacing="0" cellpadding="0" width="529" border="1"><tbody><tr><td><font size="2">net.sf.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): 2, of class: bo.AutoInfo</font></td></tr></tbody></table></span>
		</p>
		<br />
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US">
						<span style="mso-spacerun: yes">    </span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">造成无法删除的原因是</span>
				<span lang="EN-US">PEOPLE </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</span>
				<span lang="EN-US">AUTO_INFO </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">表存在着一对多（</span>
				<span lang="EN-US">one-to-many</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）关系，想要从</span>
				<span lang="EN-US">AUTO_INFO </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">删除一条记录，就必须用</span>
				<span lang="EN-US">people.getAutoInfoSet().remove(ai) </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方法为</span>
				<span lang="EN-US"> People </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">移除以“</span>
				<span lang="EN-US">A00002</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">”为条件查询出的</span>
				<span lang="EN-US">AutoInfo </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象，才能真正删除该</span>
				<span lang="EN-US">AutoInfo </span>
				<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">
						<span style="mso-spacerun: yes">    </span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">从张三的失落中回过头来，这次</span>
				<span lang="EN-US"> Hibernate </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">之旅也即将结束了。最后要体验的是删除</span>
				<span lang="EN-US">PEOPLE </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">表及其关联的</span>
				<span lang="EN-US">AUTO_INFO </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">表。<br /><br /><table style="WIDTH: 527px; HEIGHT: 100px" height="100" cellspacing="0" cellpadding="0" width="527" border="1"><tbody><tr><td><p><font size="2">package com.dao;</font></p><p><font size="2">import java.util.*;</font></p><p><font size="2">import net.sf.hibernate.*;<br />import net.sf.hibernate.cfg.*;</font></p><p><font size="2">import bo.*;</font></p><p><font size="2">public class Test {</font></p><p><font size="2"> People people;<br /> public void DoTest() {<br />  try {<br />   Configuration cfg = new Configuration().configure();<br />   SessionFactory sessions = cfg.buildSessionFactory();<br />   Session session = sessions.openSession();<br />   Transaction tx = session.beginTransaction();<br />   people =<br />    (People) session.load(People.class,new Integer(1));<br />   session.delete(people);<br />   tx.commit();<br />   session.close();<br />  } catch (Exception e) {<br />   System.out.println(e);<br />  }<br /> }<br />}</font></p></td></tr></tbody></table></span>
		</p>
		<br />
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US">
						<span style="mso-spacerun: yes">    </span>Hibernate </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的优势又一次体现出来。我们只需把一对多（</span>
				<span lang="EN-US">one-to-many</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）关系中“</span>
				<span lang="EN-US">one</span>
				<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">
						<span style="mso-spacerun: yes">    </span>
				</span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">最后，通过这次旅程，也算把</span>
				<span lang="EN-US"> Hibernate </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的特性体验了一把。作为一种</span>
				<span lang="EN-US"> O/R Mapping </span>
				<span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">实现，它是很优秀的，希望我们都可以用好它。<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/9915.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 11:38 <a href="http://www.blogjava.net/rosen/archive/2005/08/12/9915.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>我的 O/R Mapping 之旅（三）</title><link>http://www.blogjava.net/rosen/archive/2005/08/12/9914.html</link><dc:creator>Rosen</dc:creator><author>Rosen</author><pubDate>Fri, 12 Aug 2005 03:36:00 GMT</pubDate><guid>http://www.blogjava.net/rosen/archive/2005/08/12/9914.html</guid><wfw:comment>http://www.blogjava.net/rosen/comments/9914.html</wfw:comment><comments>http://www.blogjava.net/rosen/archive/2005/08/12/9914.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rosen/comments/commentRss/9914.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rosen/services/trackbacks/9914.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: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在本部分中，才真正开始对</SPAN><SPAN lang=EN-US> AUTO_INFO </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN> <SPAN lang=EN-US>PEOPLE </SPAN><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; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN></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="mso-bidi-font-weight: bold; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">Hibernate</SPAN><SPAN lang=EN-US style="mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt"> </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">跑起来，还要了解其中几个关键对象：</SPAN><SPAN lang=EN-US style="mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt"> 
<P></P></SPAN>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;</SPAN></SPAN><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">net.sf.hibernate.cfg.Configuration 的实例负责管理 </SPAN><SPAN lang=EN-US style="mso-bidi-font-weight: bold; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">Hibernate </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">配置信息，比如数据库连接、数据库</SPAN><SPAN style="mso-bidi-font-weight: bold; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt"> </SPAN><SPAN lang=EN-US style="mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">dialect</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">，还有最重要的映射文件初始化工作。</SPAN><SPAN lang=EN-US style="mso-bidi-font-weight: bold; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt"> 
<P></P></SPAN>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="mso-bidi-font-weight: bold; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">程序为了得到</SPAN><SPAN style="mso-bidi-font-weight: bold; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt"> </SPAN><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">Session 实例，必须先要得到它的工厂&nbsp;net.sf.hibernate.SessionFactory，SessionFactory </SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">的实例</SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">由</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> </SPAN><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">Configuration 构造。 
<P></P></SPAN>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; net.sf.hibernate.Session </SPAN></SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">是一切数据库操作的基础，和<SPAN lang=EN-US> JDBC 的 </SPAN></SPAN><SPAN lang=EN-US style="mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">Connection</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; mso-font-kerning: 0pt"> </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">意义一样，Session 实例由 SessionFactory 获得</SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">。<SPAN lang=EN-US> 
<P></P></SPAN></SPAN>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; net.sf.hibernate.Transaction 的实例由 Session 获得</SPAN></SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">Hibernate </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">不具备事务管理能力，</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt">Hibernate </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">将其委托给底层的</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt"> <SPAN lang=EN-US>JDBC </SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">或者</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> </SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-font-kerning: 0pt">JTA</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">，以实现事务管理和调度功能。在本文中使用 <SPAN lang=EN-US>JDBC 事务管理。</SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> 
<P></P></SPAN>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt"><SPAN style="mso-spacerun: yes"></SPAN>
<P></P></SPAN>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">把以上的知识串起来吧：<SPAN lang=EN-US> 
<P></P></SPAN></SPAN>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>
<P>
<TABLE style="WIDTH: 586px; HEIGHT: 41px" height=41 cellSpacing=0 cellPadding=0 width=586 border=1>
<TBODY>
<TR>
<TD><FONT size=2>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">Configuration cfg = new Configuration().configure(); 
<P></P></SPAN>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">SessionFactory sessions = cfg.buildSessionFactory(); 
<P></P></SPAN>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">Session session = sessions.openSession(); 
<P></P></SPAN>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">Transaction tx = session.beginTransaction();</SPAN></FONT></TD></TR></TBODY></TABLE></SPAN>&nbsp;<BR><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">程序第一幕马上出场。</SPAN></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: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">有位叫张三的人，他买了辆车。由于是第一次买车，进入车辆管理系统后要对</SPAN><SPAN lang=EN-US>AUTO_INFO </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US> PEOPLE </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">表都进行</SPAN><SPAN lang=EN-US> insert </SPAN><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; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">形成的一对多（</SPAN><SPAN lang=EN-US>one-to-many</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）关系保存如下：</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-char-indent-count: 2.0; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">
<P>
<TABLE style="WIDTH: 588px; HEIGHT: 100px" height=100 cellSpacing=0 cellPadding=0 width=588 border=1>
<TBODY>
<TR>
<TD>
<P><FONT size=2>package com.dao;</FONT></P>
<P><FONT size=2>import java.util.*;</FONT></P>
<P><FONT size=2>import net.sf.hibernate.*;<BR>import net.sf.hibernate.cfg.*;</FONT></P>
<P><FONT size=2>import bo.*;</FONT></P>
<P><FONT size=2>public class Test {</FONT></P>
<P><FONT size=2>&nbsp;List list;<BR>&nbsp;AutoInfo ai=new AutoInfo();<BR>&nbsp;&nbsp;&nbsp; People people=new People();<BR>&nbsp;public void DoTest() {<BR>&nbsp;&nbsp;try {<BR>&nbsp;&nbsp;&nbsp;Configuration cfg = new Configuration().configure();<BR>&nbsp;&nbsp;&nbsp;SessionFactory sessions = cfg.buildSessionFactory();<BR>&nbsp;&nbsp;&nbsp;Session session = sessions.openSession();<BR>&nbsp;&nbsp;&nbsp;Transaction tx = session.beginTransaction();<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;people.setAddress("中国");<BR>&nbsp;&nbsp;&nbsp;people.setName("张三");<BR>&nbsp;&nbsp;&nbsp;people.addToAutoInfoSet(ai);<BR>&nbsp;&nbsp;&nbsp;ai.setLicensePlate("A00001");<BR>&nbsp;&nbsp;&nbsp;ai.setOwnerNo(people);<BR>&nbsp;&nbsp;&nbsp;session.save(people);<BR>&nbsp;&nbsp;&nbsp;tx.commit();<BR>&nbsp;&nbsp;&nbsp;session.close();<BR>&nbsp;&nbsp;} catch (Exception e) {<BR>&nbsp;&nbsp;&nbsp;System.out.println(e);<BR>&nbsp;&nbsp;}<BR>&nbsp;}<BR>}</FONT></P></TD></TR></TBODY></TABLE></P></SPAN>
<P></P>
<P><SPAN style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">&nbsp;&nbsp;&nbsp; 分别设置好 </SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-weight: bold; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">AutoInfo</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">、<SPAN lang=EN-US>People 对象属性后，调用 </SPAN></SPAN><SPAN lang=EN-US style="mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">Session.save() </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">方法保存，然后事务提交，最后关闭</SPAN><SPAN style="mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt"> <SPAN lang=EN-US>Session</SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; 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="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">程序第二幕出场。</SPAN></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: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">张三后来做生意，自己经营得很好，打算再买辆车跑运输。对于第二次买车，车辆管理系统的</SPAN><SPAN lang=EN-US> PEOPLE </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">表原本已经记录了他的基本信息，遂不对</SPAN><SPAN lang=EN-US> PEOPLE </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">表操作。只向</SPAN> <SPAN lang=EN-US>AUTO_INFO</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">表</SPAN> <SPAN lang=EN-US>insert </SPAN><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; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">形成的一对多（</SPAN><SPAN lang=EN-US>one-to-many</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）关系保存如下：</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 20pt; TEXT-ALIGN: left; mso-char-indent-count: 2.0; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">
<P>
<TABLE style="WIDTH: 587px; HEIGHT: 100px" height=100 cellSpacing=0 cellPadding=0 width=587 border=1>
<TBODY>
<TR>
<TD>
<P><FONT size=2>package com.dao;</FONT></P>
<P><FONT size=2>import java.util.*;</FONT></P>
<P><FONT size=2>import net.sf.hibernate.*;<BR>import net.sf.hibernate.cfg.*;</FONT></P>
<P><FONT size=2>import bo.*;</FONT></P>
<P><FONT size=2>public class Test {</FONT></P>
<P><FONT size=2>&nbsp;List list;<BR>&nbsp;AutoInfo ai = new AutoInfo();<BR>&nbsp;People people = new People();<BR>&nbsp;public void DoTest() {<BR>&nbsp;&nbsp;try {<BR>&nbsp;&nbsp;&nbsp;Configuration cfg = new Configuration().configure();<BR>&nbsp;&nbsp;&nbsp;SessionFactory sessions = cfg.buildSessionFactory();<BR>&nbsp;&nbsp;&nbsp;Session session = sessions.openSession();<BR>&nbsp;&nbsp;&nbsp;Transaction tx = session.beginTransaction();<BR>&nbsp;&nbsp;&nbsp;people =<BR>&nbsp;&nbsp;&nbsp;&nbsp;(People) session<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.find(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"from People where OWNER_ID=1")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.get(0);<BR>&nbsp;&nbsp;&nbsp;ai.setLicensePlate("A00002");<BR>&nbsp;&nbsp;&nbsp;ai.setOwnerNo(people);<BR>&nbsp;&nbsp;&nbsp;people.getAutoInfoSet().add(ai);<BR>&nbsp;&nbsp;&nbsp;session.save(people);<BR>&nbsp;&nbsp;&nbsp;tx.commit();<BR>&nbsp;&nbsp;&nbsp;session.close();<BR>&nbsp;&nbsp;} catch (Exception e) {<BR>&nbsp;&nbsp;&nbsp;System.out.println(e);<BR>&nbsp;&nbsp;}<BR>&nbsp;}<BR>}</FONT></P></TD></TR></TBODY></TABLE></P></SPAN>
<P></P>
<P><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">&nbsp;&nbsp;&nbsp; session.find() 方法返回一个 List 接口的实例，里面封装着 PO，其中的 </SPAN><SPAN lang=EN-US style="mso-ascii-font-family: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">“</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">from People where OWNER_ID=1</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; mso-ascii-font-family: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">”</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">就是大名鼎鼎的<SPAN lang=EN-US> HQL(</SPAN></SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-font-weight: bold; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">Hibernate Query Language</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">) 了，是不是很像 SQL 呢？PEOPLE 表和 AUTO_INFO 表存在一对多关系，也就需要 People 对象来持有多个 AutoInfo 对象（以&nbsp;Set </SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">接口的</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">实例封装，参看<SPAN lang=EN-US>People类源代码），再通过 </SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">people.getAutoInfoSet().add(ai) </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">为 <SPAN lang=EN-US>AUTO_INFO 表添加一条新纪录。好了，执行完以后，再检查数据库吧。</SPAN></SPAN></P>
<P></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">这段代码<SPAN lang=EN-US> 
<P></P></SPAN></SPAN>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">
<TABLE style="WIDTH: 579px; HEIGHT: 23px" height=23 cellSpacing=0 cellPadding=0 width=579 border=1>
<TBODY>
<TR>
<TD><FONT size=2>people =&nbsp;(People) session.find("from People where OWNER_ID=1").get(0);</FONT></TD></TR></TBODY></TABLE><BR>可以和</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 5.25pt; TEXT-INDENT: -5.25pt; TEXT-ALIGN: left; mso-char-indent-count: -.5; mso-layout-grid-align: none" align=left><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">
<TABLE style="WIDTH: 573px; HEIGHT: 23px" height=23 cellSpacing=0 cellPadding=0 width=573 border=1>
<TBODY>
<TR>
<TD><FONT size=2>people =(People) session.load(People.class,new Integer(1));</FONT></TD></TR></TBODY></TABLE><BR>互换。</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">在本例中 <SPAN lang=EN-US>List 接口实例 size() 为 1，即其中只有一个 PO；而 </SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 'Courier New'; mso-font-kerning: 0pt">session.load() </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">是根据持久对象和主键来返回相应 <SPAN lang=EN-US>PO，也只是单个。所以这两种方式返回的都是相同 PO。采用哪种方式由你决定。</SPAN></SPAN></P>
<P></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-char-indent-count: 2.0; mso-layout-grid-align: none" align=left><SPAN style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">到这里，也许你会有这样的想法：“应该可以直接向 <SPAN lang=EN-US>AUTO_INFO 表插入记录，不通过 People 对象中转，像写 SQL 一样 Easy。” 错了！以前直接写 SQL 是可以办到的，不过现在我们用的可是 Hibernate ，一切都要以对象行事，看见 </SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">ai.setOwnerNo(people) </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">了吗？传入参数是个<SPAN lang=EN-US> People 对象实例，不是简单的字段喔。</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-char-indent-count: 2.0; mso-layout-grid-align: none" align=left><SPAN style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt"><SPAN lang=EN-US></SPAN></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: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">程序第三幕出场。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-char-indent-count: 2.0; mso-layout-grid-align: none" align=left><SPAN style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">呵呵，这个</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">第三幕是最简单的了，第一种一对多（</SPAN><SPAN lang=EN-US>one-to-many</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）的查询：</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-char-indent-count: 2.0; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">
<P>
<TABLE style="WIDTH: 588px; HEIGHT: 100px" height=100 cellSpacing=0 cellPadding=0 width=588 border=1>
<TBODY>
<TR>
<TD>
<P><FONT size=2>package com.dao;</FONT></P>
<P><FONT size=2>import java.util.*;</FONT></P>
<P><FONT size=2>import net.sf.hibernate.*;<BR>import net.sf.hibernate.cfg.*;</FONT></P>
<P><FONT size=2>import bo.*;</FONT></P>
<P><FONT size=2>public class Test {</FONT></P>
<P><FONT size=2>&nbsp;List list;<BR>&nbsp;AutoInfo ai = new AutoInfo();<BR>&nbsp;People people = new People();<BR>&nbsp;public void DoTest() {<BR>&nbsp;&nbsp;try {<BR>&nbsp;&nbsp;&nbsp;Configuration cfg = new Configuration().configure();<BR>&nbsp;&nbsp;&nbsp;SessionFactory sessions = cfg.buildSessionFactory();<BR>&nbsp;&nbsp;&nbsp;Session session = sessions.openSession();<BR>&nbsp;&nbsp;&nbsp;List list =<BR>&nbsp;&nbsp;&nbsp;&nbsp;session.find(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"select ai from AutoInfo as ai where ai.OwnerNo.Id=1");<BR>&nbsp;&nbsp;&nbsp;for (int i = 0; i &lt; list.size(); i++) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;ai=(AutoInfo)list.get(i);<BR>&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(ai.getLicensePlate());<BR>&nbsp;&nbsp;&nbsp;&nbsp;people=ai.getOwnerNo();<BR>&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(people.getName());<BR>&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(people.getAddress());<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;session.close();<BR>&nbsp;&nbsp;} catch (Exception e) {<BR>&nbsp;&nbsp;&nbsp;System.out.println(e);<BR>&nbsp;&nbsp;}<BR>&nbsp;}<BR>}</FONT></P></TD></TR></TBODY></TABLE>&nbsp;&nbsp;<BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">&nbsp;&nbsp;&nbsp; 到了年底，查查张三一共有多少辆车。</SPAN><SPAN lang=EN-US style="mso-ascii-font-family: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">”</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">select ai from AutoInfo as ai where ai.OwnerNo.Id=1</SPAN><SPAN lang=EN-US style="mso-ascii-font-family: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">”</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">，这句<SPAN lang=EN-US> HQL 要找的是 AutoInfo 对象，而传统 SQL 这么写：“select p.name,p.address,ai.license_plate from people p,auto_info ai where p.owner_id=1”。由于 AUTO_INFO 表是“many”表，而 PEOPLE 表是“one”表，我的做法是以“many”表为基础返回它的多个 PO，其中再持有“one”表的信息。“ai.OwnerNo.Id=1”就是说通过主键参数为“1”的 PEOPLE 表记录来取出相应 AUTO_INFO 表记录。</SPAN></SPAN></P>
<P></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-char-indent-count: 2.0; mso-layout-grid-align: none" align=left><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对于一对多（</SPAN><SPAN lang=EN-US>one-to-many</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）关系，还有第二种查询方式：</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">
<P>
<TABLE style="WIDTH: 584px; HEIGHT: 100px" height=100 cellSpacing=0 cellPadding=0 width=584 border=1>
<TBODY>
<TR>
<TD>
<P><FONT size=2>package com.dao;</FONT></P>
<P><FONT size=2>import java.util.*;</FONT></P>
<P><FONT size=2>import net.sf.hibernate.*;<BR>import net.sf.hibernate.cfg.*;</FONT></P>
<P><FONT size=2>import bo.*;</FONT></P>
<P><FONT size=2>public class Test {</FONT></P>
<P><FONT size=2>&nbsp;AutoInfo ai = new AutoInfo();<BR>&nbsp;People people = new People();<BR>&nbsp;public void DoTest() {<BR>&nbsp;&nbsp;try {<BR>&nbsp;&nbsp;&nbsp;Configuration cfg = new Configuration().configure();<BR>&nbsp;&nbsp;&nbsp;SessionFactory sessions = cfg.buildSessionFactory();<BR>&nbsp;&nbsp;&nbsp;Session session = sessions.openSession();<BR>&nbsp;&nbsp;&nbsp;people = (People) session.load(People.class, new Integer(1));<BR>&nbsp;&nbsp;&nbsp;Iterator iterator = people.getAutoInfoSet().iterator();<BR>&nbsp;&nbsp;&nbsp;System.out.println(people.getName());<BR>&nbsp;&nbsp;&nbsp;System.out.println(people.getAddress());<BR>&nbsp;&nbsp;&nbsp;while (iterator.hasNext()) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;ai = (AutoInfo) iterator.next();<BR>&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(ai.getLicensePlate());<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;session.close();<BR>&nbsp;&nbsp;} catch (Exception e) {<BR>&nbsp;&nbsp;&nbsp;System.out.println(e);<BR>&nbsp;&nbsp;}<BR>&nbsp;}<BR>}</FONT></P></TD></TR></TBODY></TABLE></SPAN></P>
<P></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>people = (People) session.load(People.class, new Integer(1)) 取出单个 People 对象，其中持有以 Set 封装的若干 AutoInfo 对象实例，Iterator iterator = people.getAutoInfoSet().iterator() 把 Set 立即转化为 Iterator ，最后用 while (iterator.hasNext()) 循环取出其中的车牌号码。</SPAN></P>
<P></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>第一</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">种一对多（</SPAN><SPAN lang=EN-US>one-to-many</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）的查询实际上我把它转换成了多对一（</SPAN><SPAN lang=EN-US>many -to- one</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）的查询。这种转换后有两个缺点：一、由</SPAN><SPAN lang=EN-US> HQL </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">转为</SPAN><SPAN lang=EN-US> SQL </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">输出时，打印的</SPAN><SPAN lang=EN-US> SQL </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">条数多于直接一对多（</SPAN><SPAN lang=EN-US>one-to-many</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: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">People 对象存在着大量冗余（只需要一个实例，结果取出了 List.size() 个相同的实例）。我们知道，数据库的性能是有限的，构造对象的代价是高昂的，所以应尽量减少不必要的性能开销。</SPAN></P>
<P></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>虽然我个人不建议把</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">一对多（</SPAN><SPAN lang=EN-US>one-to-many</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）查询转换成多对一（</SPAN><SPAN lang=EN-US>many -to- one</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）查询，但事实上有些开发团队却乐意采用，即使他们知道性能有略微的降低。在还没有更深入研究之前，各位看官有何看法呢？<BR><BR><BR><STRONG><FONT color=#ff0000 size=2>请注意！引用、转贴本文应注明原作者：Rosen Jiang 以及出处：</FONT></STRONG><A href="http://www.blogjava.net/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/9914.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 11:36 <a href="http://www.blogjava.net/rosen/archive/2005/08/12/9914.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>我的 O/R Mapping 之旅（二）</title><link>http://www.blogjava.net/rosen/archive/2005/08/12/9911.html</link><dc:creator>Rosen</dc:creator><author>Rosen</author><pubDate>Fri, 12 Aug 2005 03:30:00 GMT</pubDate><guid>http://www.blogjava.net/rosen/archive/2005/08/12/9911.html</guid><wfw:comment>http://www.blogjava.net/rosen/comments/9911.html</wfw:comment><comments>http://www.blogjava.net/rosen/archive/2005/08/12/9911.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.blogjava.net/rosen/comments/commentRss/9911.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rosen/services/trackbacks/9911.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 在上一部分我只讲到如何通过数据库中的表生成映射文件和														POJO												。在这一部分中，我将讲解映射文件。																																								 																																														    ...&nbsp;&nbsp;<a href='http://www.blogjava.net/rosen/archive/2005/08/12/9911.html'>阅读全文</a><img src ="http://www.blogjava.net/rosen/aggbug/9911.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 11:30 <a href="http://www.blogjava.net/rosen/archive/2005/08/12/9911.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>我的 O/R Mapping 之旅（一）</title><link>http://www.blogjava.net/rosen/archive/2005/08/12/9910.html</link><dc:creator>Rosen</dc:creator><author>Rosen</author><pubDate>Fri, 12 Aug 2005 03:26:00 GMT</pubDate><guid>http://www.blogjava.net/rosen/archive/2005/08/12/9910.html</guid><wfw:comment>http://www.blogjava.net/rosen/comments/9910.html</wfw:comment><comments>http://www.blogjava.net/rosen/archive/2005/08/12/9910.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rosen/comments/commentRss/9910.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rosen/services/trackbacks/9910.html</trackback:ping><description><![CDATA[
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">
						<span style="mso-spacerun: yes">    </span>
				</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">首先要感谢我所在的</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> Team </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">意识到了传统</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> JDBC </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">开发的种种不足，转而开始关注</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> O/R Mapping </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">领域的成果。说到</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> O/R Mapping</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，我认为在对象数据库还没有真正成熟的时候它是一个不错的选择，看看</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> SUN </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> JDO 2.0 </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">规范吧，它的即将发布将会把这个领域推向更高的境界。再看看我们的开源社区呢，喔！发现了</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> Hibernate</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">！从现在开始，我的焦点将放在</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> Hibernate </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">上面，一个优秀的</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">O/R Mapping </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">工具。</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">
						<p>
						</p>
				</span>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">
						<span style="mso-spacerun: yes">    </span>
				</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在没有正式开始旅行之前，让我们区分几个名词。</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">POJO</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">：在</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> Hibernate </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中代表包含</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> Seter</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">Geter </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这些最基本操作的值对象。而</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> BO</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">：代表包含一些业务逻辑的值对象，它的作用域很大，也就是说</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> BO </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在充当持久类的同时可以传到</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> UI </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">层。</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">PO</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">：代表持久对象，是纳入</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> Hibernate </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">管理框架中的，在一定程度上可以和值对象的概念互换，值对象经过</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> Hibernate </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">进行处理，就变成了</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> PO </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">Hibernate </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">配置文件：</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">hibernate.cfg.xml </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">或</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> hibernate.properties</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，不过推荐使用</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> XML </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">格式。映射文件</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> *.hbm.xml</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">：映射文件的作用是将</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> POJO </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">与关系型数据库数据相绑定，作为一个桥梁。另外，为数据库中的表进行手工编写映射文件可不是件好差事，幸好开源社区中也有一群同样想法的人，他们开发了</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> hibernateSynchronizer </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">映射工具，可到</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> http://www.binamics.com/hibernatesync/eclipse2.1/ </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">下载。</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">
						<p>
						</p>
				</span>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">
						<span style="mso-spacerun: yes">    </span>
				</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">好了，现在去</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> http://www.hibernate.org </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">下载</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> Hibernate </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的开发包（目前的版本是</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> 2.1.6</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）。接着打开</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> Eclipse 2.1</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，在更新管理器中安装</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> hibernateSynchronizer</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。据说</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> Eclipse 3.0 </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">已内置映射工具，不过我没有试。安装完毕后，新建一个</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> Web </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">应用程序</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> HibernateTest</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，接着为这个应用程序添加</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> Hibernate </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类库</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> hibernate-2.1.6\hibernate-2.1\hibernate2.jar </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">及其依赖类库、数据库连接包，强烈建议把</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> hibernate-2.1.6\hibernate-2.1\lib </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; 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-SIZE: 10pt; COLOR: black">
						<shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f">
						</shapetype>
						<stroke joinstyle="miter">
						</stroke>
						<formulas>
						</formulas>
						<f eqn="if lineDrawn pixelLineWidth 0">
						</f>
						<f eqn="sum @0 1 0">
						</f>
						<f eqn="sum 0 0 @1">
						</f>
						<f eqn="prod @2 1 2">
						</f>
						<f eqn="prod @3 21600 pixelWidth">
						</f>
						<f eqn="prod @3 21600 pixelHeight">
						</f>
						<f eqn="sum @0 0 1">
						</f>
						<f eqn="prod @6 1 2">
						</f>
						<f eqn="prod @7 21600 pixelWidth">
						</f>
						<f eqn="sum @8 21600 0">
						</f>
						<f eqn="prod @7 21600 pixelHeight">
						</f>
						<f eqn="sum @10 21600 0">
						</f>
						<path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect">
						</path>
						<lock v:ext="edit" aspectratio="t">
						</lock>      <shape id="_x0000_i1028" style="WIDTH: 414.75pt; HEIGHT: 285.75pt" type="#_x0000_t75"></shape><imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image001.jpg" o:title="1"></imagedata><img height="419" alt="" src="http://blog.csdn.net/images/blog_csdn_net/rosen/68948/o_1.jpg" width="608" border="0" /></span>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">
						<span style="mso-spacerun: yes">    </span>
				</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">接着使用</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> hibernateSynchronizer </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">来生成</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> hibernate.cfg.xml </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">文件，新建——</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">&gt;</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">其他——</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">&gt;Hibernate Configuration File</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，我使用的是</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> SQL Server </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">数据库，各项配置参数见下图：<br /></span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">
						<p>
						</p>
				</span>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">   <shape id="_x0000_i1029" style="WIDTH: 414.75pt; HEIGHT: 403.5pt" type="#_x0000_t75"></shape><imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image003.jpg" o:title="2"></imagedata><br /><img height="543" alt="" src="http://blog.csdn.net/images/blog_csdn_net/rosen/68948/o_2.jpg" width="559" border="0" /></span>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">     生成出来的</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> hibernate.cfg.xml </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">文件：<br /></span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">
						<p>
						</p>
				</span>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">   <img height="372" alt="" src="http://blog.csdn.net/images/blog_csdn_net/rosen/68948/o_3.jpg" width="561" border="0" /></span>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">
						<span style="mso-spacerun: yes">    </span>
				</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在项目的</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> src </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">目录下新建四个包，分别是</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">bo</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">bo.base</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">bo.mapping</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">com.dao</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，具体什么作用，到时候他们都会一一呈献。在开始映射文件前还要做一件事，为应用程序</span>
				<span style="FONT-SIZE: 10pt; COLOR: black">
						<span lang="EN-US">HibernateTest </span>
				</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">配置</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> hibernateSynchronizer </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，我更喜欢自己写</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> DAO </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，所以没有配置</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> Data Access Objects</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; 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-SIZE: 10pt; COLOR: black"> <img height="316" alt="" src="http://blog.csdn.net/images/blog_csdn_net/rosen/68948/o_4.jpg" width="648" border="0" /></span>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">      被映射的表</span>
				<span style="FONT-SIZE: 10pt; COLOR: black">
						<span lang="EN-US">AutoInfo </span>
				</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">结构如下，</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">id</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">为其主键：</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">
						<p>
						</p>
				</span>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">
						<p>                  <img height="241" alt="" src="http://blog.csdn.net/images/blog_csdn_net/rosen/68948/o_5.jpg" width="322" border="0" /></p>
				</span>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">
						<span style="mso-spacerun: yes">    </span>
				</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">新建——</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">&gt;</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">其他——</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">&gt;Hibernate Mapping File</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，配置好参数再“</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">Refresh</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">”后，选择要映射的表，注意千万不要在</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black"> 800*600 </span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">下映射文件！否则有些按钮不会出现，各项配置参数见下图：</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">
						<p>
						</p>
				</span>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">
						<p>    <img height="659" alt="" src="http://blog.csdn.net/images/blog_csdn_net/rosen/68948/o_6.jpg" width="499" border="0" /></p>
				</span>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">       终于、终于，映射文件</span>
				<span style="FONT-SIZE: 10pt; COLOR: black">
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体">AutoInfo.hbm.xml</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">
				</span>
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">终于出来了！</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black">
						<p>
						</p>
				</span>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<b>
						<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体">
								<p>
								</p>
								<table style="WIDTH: 585px; HEIGHT: 100px" height="100" cellspacing="0" cellpadding="0" width="585" border="1">
										<tbody>
												<tr>
														<td>
																<p>
																		<font size="2">    &lt;?xml version="1.0"?&gt;<br />&lt;!DOCTYPE hibernate-mapping PUBLIC<br /> "-//Hibernate/Hibernate Mapping DTD//EN"<br /> "</font>
																		<a href="http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
																				<font color="#000080" size="2">http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd</font>
																		</a>
																		<font size="2">" &gt;</font>
																</p>
																<p>
																		<font size="2">&lt;hibernate-mapping package="bo.base"&gt;<br /> &lt;class name="AutoInfo" table="AutoInfo"&gt;<br />  &lt;property<br />   column="owner_dept"<br />   length="500"<br />   name="OwnerDept"<br />   not-null="false"<br />   type="string"<br />   /&gt;<br />  &lt;property<br />   column="license_plate"<br />   length="50"<br />   name="LicensePlate"<br />   not-null="false"<br />   type="string"<br />   /&gt;<br />  &lt;property<br />   column="owner"<br />   length="50"<br />   name="Owner"<br />   not-null="false"<br />   type="string"<br />   /&gt;<br />  &lt;property<br />   column="owner_adderss"<br />   length="1000"<br />   name="OwnerAdderss"<br />   not-null="false"<br />   type="string"<br />   /&gt;<br />  &lt;property<br />   column="id"<br />   length="18"<br />   name="Id"<br />   not-null="true"<br />   type="integer"<br />   /&gt;<br /> &lt;/class&gt;<br />&lt;/hibernate-mapping&gt;</font>
																</p>
														</td>
												</tr>
										</tbody>
								</table>
						</span>
				</b>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体">
						<span style="mso-spacerun: yes">    </span>需要修改一下 AutoInfo.hbm.xml 文件为其定义主键，把： 
<p></p></span>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体">
						<p>
						</p>
						<table style="WIDTH: 584px; HEIGHT: 100px" height="100" cellspacing="0" cellpadding="0" width="584" border="1">
								<tbody>
										<tr>
												<td>
														<font size="2">    &lt;property<br />     column="id"<br />     length="18"<br />     name="Id"<br />     not-null="true"<br />     type="integer"<br />    /&gt;</font>
												</td>
										</tr>
								</tbody>
						</table>
				</span>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 20pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 2.0" align="left">
				<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体">替换为：<span lang="EN-US"><p></p></span></span>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体">
						<p>
						</p>
						<table style="WIDTH: 584px; HEIGHT: 70px" height="70" cellspacing="0" cellpadding="0" width="584" border="1">
								<tbody>
										<tr>
												<td>
														<font size="2">    &lt;id name="Id" column="id" type="integer"&gt;<br />       &lt;generator class="native"/&gt;<br />    &lt;/id&gt;</font>
												</td>
										</tr>
								</tbody>
						</table>    </span>    </p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体">
						<span style="mso-spacerun: yes">    </span>再接再厉，为映射文件生成 POJO。修改 hibernate.cfg.xml 文件在 &lt;/session-factory&gt; 标签的上面加上刚才映射的文件 &lt;mapping resource="bo/mapping/AutoInfo.hbm.xml" /&gt;。接着在“包资源管理器”中点击 AutoInfo.hbm.xml 右键，Hibernate Synchronizer——&gt;Synchronize Files。再看看 src 中的包：<br /><p></p></span>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体">
						<p>                <img height="86" alt="" src="http://blog.csdn.net/images/blog_csdn_net/rosen/68948/t_7.jpg" width="120" border="0" /></p>
				</span>                </p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体">
						<span style="mso-spacerun: yes">
						</span>
						<p>
						</p>
				</span>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align="left">
				<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体">
						<span style="mso-spacerun: yes">    </span>
				</span>
				<b style="mso-bidi-font-weight: normal">
						<span lang="EN-US" style="COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体">O/R Mapping 的旅程先到这里吧，后面的路将会越来越坎坷！你准备好了吗？<br /><br /><br /><font color="#ff0000" size="2">请注意！引用、转贴本文应注明原作者：Rosen Jiang 以及出处：</font><a href="/rosen"><font color="#ff0000" size="2"><strong>http://www.blogjava.net/rosen</strong></font></a></span>
				</b>
		</p>
<img src ="http://www.blogjava.net/rosen/aggbug/9910.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 11:26 <a href="http://www.blogjava.net/rosen/archive/2005/08/12/9910.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>