﻿<?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-jinfeng_wang-随笔分类-hibernate</title><link>http://www.blogjava.net/jinfeng_wang/category/481.html</link><description>G-G-S,D-D-U!</description><language>zh-cn</language><lastBuildDate>Tue, 27 Feb 2007 10:06:06 GMT</lastBuildDate><pubDate>Tue, 27 Feb 2007 10:06:06 GMT</pubDate><ttl>60</ttl><item><title>Mapping collections of value types </title><link>http://www.blogjava.net/jinfeng_wang/archive/2005/04/11/3132.html</link><dc:creator>jinfeng_wang</dc:creator><author>jinfeng_wang</author><pubDate>Mon, 11 Apr 2005 06:12:00 GMT</pubDate><guid>http://www.blogjava.net/jinfeng_wang/archive/2005/04/11/3132.html</guid><wfw:comment>http://www.blogjava.net/jinfeng_wang/comments/3132.html</wfw:comment><comments>http://www.blogjava.net/jinfeng_wang/archive/2005/04/11/3132.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jinfeng_wang/comments/commentRss/3132.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jinfeng_wang/services/trackbacks/3132.html</trackback:ping><description><![CDATA[<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><B><I><SPAN lang=EN-US style="FONT-SIZE: 13pt; FONT-FAMILY: Arial; mso-font-kerning: 0pt">Mapping collections of value types (from 《hibernate in action》chapter 6)<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></I></B></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: 12pt; FONT-FAMILY: Arial; mso-font-kerning: 0pt; mso-bidi-font-size: 13.0pt">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 13.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">这里所举的例子，都是基于这样的一个情景，</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: Arial; mso-font-kerning: 0pt; mso-bidi-font-size: 13.0pt">Item</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 13.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">中包含有</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: Arial; mso-font-kerning: 0pt; mso-bidi-font-size: 13.0pt">Images</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 13.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-font-kerning: 0pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 8pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 1.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;<SPAN style="COLOR: red">set</SPAN> name="images" lazy="true" table="ITEM_IMAGE"&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;key column="ITEM_ID"/&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;element type="string" column="FILENAME" not-null="true"/&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 8pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 1.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;/set&gt;</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-FAMILY: 宋体; mso-font-kerning: 0pt; 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="mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">&lt;key&gt;</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-font-kerning: 0pt; 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="mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">ITEM_ID</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-font-kerning: 0pt; 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="mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">&lt;elememt&gt;</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-font-kerning: 0pt; 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="mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">&lt;set&gt;</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-font-kerning: 0pt; 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="mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt"><o:p></o:p></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="mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 8pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 1.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;<SPAN style="COLOR: red">idbag</SPAN> name="images" lazy="true" table="ITEM_IMAGE"&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;collection-id type="long" column="ITEM_IMAGE_ID"&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 44.95pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 5.62; mso-char-indent-size: 7.95pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;generator class="sequence"/&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;/collection-id&gt;</SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;key column="ITEM_ID"/&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;element type="string" column="FILENAME" not-null="true"/&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 8pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 1.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;/idbag&gt;</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt"><o:p></o:p></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-SIZE: 9.5pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">ITEM_IMAGE_ID</SPAN><SPAN style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Courier; mso-hansi-font-family: Courier">为主键，而</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9.5pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">ITEM_ID</SPAN><SPAN style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Courier; mso-hansi-font-family: Courier">则为外键，</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9.5pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;element&gt;</SPAN><SPAN style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Courier; mso-hansi-font-family: Courier">元素不变，这就允许集合中的数据重复。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US>&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 8pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 1.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;<SPAN style="COLOR: red">list</SPAN> name="images" lazy="true" table="ITEM_IMAGE"&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;key column="ITEM_ID"/&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;index column="POSITION"/&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;element type="string" column="FILENAME" not-null="true"/&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 8pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 1.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;/list&gt;<o:p></o:p></SPAN></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: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这里为</SPAN><SPAN lang=EN-US>ITEM_IMAGE</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">表添加了</SPAN><SPAN lang=EN-US>index</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，整个表的主键是</SPAN><SPAN lang=EN-US>ITEM_ID</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>POSITION</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">构成的复合主键，它允许集合中的数据根据</SPAN><SPAN lang=EN-US>POSITION</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>&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 8pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 1.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;<SPAN style="COLOR: red">map</SPAN> name="images"<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">lazy="true"<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">table="ITEM_IMAGE"<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: Courier; mso-font-kerning: 0pt">sort="natural"</SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;key column="ITEM_ID"/&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;index column="IMAGE_NAME" type="string"/&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;element type="string" column="FILENAME" not-null="true"/&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 8pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 1.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;/map&gt;</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt"><o:p></o:p></SPAN></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: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这里为</SPAN><SPAN lang=EN-US>ITEM_IMAGE</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">表添加了</SPAN><SPAN lang=EN-US>index</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，整个表的主键是</SPAN><SPAN lang=EN-US>ITEM_ID</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>POSITION</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">构成的复合主键，它允许集合中的数据根据</SPAN><SPAN lang=EN-US>sort</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">指定的内容进行排序，这里允许用户对</SPAN><SPAN lang=EN-US>sort</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>&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 8pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 1.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;map name="images"<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">lazy="true"<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">table="ITEM_IMAGE"<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: Courier; mso-font-kerning: 0pt">order-by="IMAGE_NAME asc"</SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;key column="ITEM_ID"/&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;index column="IMAGE_NAME" type="string"/&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;element type="string" column="FILENAME" not-null="true"/&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 8pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 1.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;/map&gt;<o:p></o:p></SPAN></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: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这里采用的是</SPAN><SPAN lang=EN-US>orbder-by</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，注意</SPAN><SPAN lang=EN-US>sort</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>order-by</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的区别。</SPAN><SPAN lang=EN-US>Sort</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是在内存中使用</SPAN><SPAN lang=EN-US>comparator</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">进行排序，而</SPAN><SPAN lang=EN-US>order-by</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></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US>&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 8pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 1.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;<SPAN style="COLOR: red">set</SPAN> name="images"<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">lazy="true"<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">table="ITEM_IMAGE"<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">order-by="IMAGE_NAME asc"&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;key column="ITEM_ID"/&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;<SPAN style="COLOR: red">composite-element</SPAN> class="<SPAN style="COLOR: red">Image</SPAN>"&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 40pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 5.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;property name="name" column="IMAGE_NAME" not-null="true"/&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 40pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 5.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;property name="filename" column="FILENAME" not-null="true"/&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 40pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 5.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;property name="sizeX" column="SIZEX" not-null="true"/&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 40pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 5.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;property name="sizeY" column="SIZEY" not-null="true"/&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;/composite-element&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 8pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 1.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;/set&gt;</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt"><o:p></o:p></SPAN></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: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这里定义了一个新的</SPAN><SPAN lang=EN-US>Image</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类，它不是实体类</SPAN><SPAN lang=EN-US>(entity class)</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，而是一个简单的值类型</SPAN><SPAN lang=EN-US>(value type)</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，仅仅是父实体的一个</SPAN><SPAN lang=EN-US>component</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，其生命周期完全由包含其的父实体</SPAN><SPAN lang=EN-US> (parent entity) ITEM</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">控制。这里</SPAN><SPAN lang=EN-US>Image</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-SIZE: 9.5pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">ITEM_ID</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</SPAN><SPAN style="mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt"> </SPAN><SPAN lang=EN-US style="FONT-SIZE: 9.5pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">IMAGE_NAME</SPAN><SPAN style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Courier; mso-hansi-font-family: Courier">、</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9.5pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">FILENAME</SPAN><SPAN style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Courier; mso-hansi-font-family: Courier">、</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9.5pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">SIZEX</SPAN><SPAN style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Courier; mso-hansi-font-family: Courier">、和</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9.5pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">SIZEY</SPAN><SPAN style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Courier; mso-hansi-font-family: Courier">。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9.5pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt"><o:p></o:p></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-SIZE: 9.5pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN lang=EN-US>&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 8pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 1.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;set name="images"<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">lazy="true"<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">table="ITEM_IMAGE"<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">order-by="IMAGE_NAME asc"&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;key column="ITEM_ID"/&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;composite-element class="Image"&gt;<SPAN style="COLOR: red"><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 40pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 5.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; COLOR: red; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;parent name="item"/&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 40pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 5.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;property name="name" column="IMAGE_NAME" not-null="true"/&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 40pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 5.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;property name="filename" column="FILENAME" not-null="true"/&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 40pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 5.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;property name="sizeX" column="SIZEX" not-null="true"/&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 40pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 5.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;property name="sizeY" column="SIZEY" not-null="true"/&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 3.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;/composite-element&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="BACKGROUND: #d9d9d9; MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 8pt; TEXT-ALIGN: left; mso-layout-grid-align: none; mso-char-indent-count: 1.0; mso-char-indent-size: 8.0pt" align=left><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;/set&gt;</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt"><o:p></o:p></SPAN></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: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">前面定义的</SPAN><SPAN lang=EN-US>IMAGE</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类中，并不包含有对父实体</SPAN><SPAN lang=EN-US>ITEM</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的引用。也就是说，只可以从</SPAN><SPAN lang=EN-US>ITEM</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中导航到</SPAN><SPAN lang=EN-US>IMAGE</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中，但是在</SPAN><SPAN lang=EN-US>IMAGE</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">无法得到</SPAN><SPAN lang=EN-US>ITEM</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。这可以通过</SPAN><SPAN lang=EN-US>&lt;parent&gt;</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">实现。这样</SPAN><SPAN lang=EN-US>IMAGE</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类中就含有一个数据成员</SPAN><SPAN lang=EN-US>item</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 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>IMAGE</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">后，但是如同普通的值类型一样，</SPAN><SPAN lang=EN-US>IMAGE</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象的</SPAN><SPAN lang=EN-US>item</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是</SPAN><SPAN lang=EN-US>null</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，你无法从</SPAN><SPAN lang=EN-US>component</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如此直接得到其父对象，这必须由通过父－子关系的</SPAN><SPAN lang=EN-US>entity</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">完成。</SPAN></P><img src ="http://www.blogjava.net/jinfeng_wang/aggbug/3132.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jinfeng_wang/" target="_blank">jinfeng_wang</a> 2005-04-11 14:12 <a href="http://www.blogjava.net/jinfeng_wang/archive/2005/04/11/3132.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Hibernate Transaction Theory released.</title><link>http://www.blogjava.net/jinfeng_wang/archive/2005/04/11/3115.html</link><dc:creator>jinfeng_wang</dc:creator><author>jinfeng_wang</author><pubDate>Mon, 11 Apr 2005 03:59:00 GMT</pubDate><guid>http://www.blogjava.net/jinfeng_wang/archive/2005/04/11/3115.html</guid><wfw:comment>http://www.blogjava.net/jinfeng_wang/comments/3115.html</wfw:comment><comments>http://www.blogjava.net/jinfeng_wang/archive/2005/04/11/3115.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jinfeng_wang/comments/commentRss/3115.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jinfeng_wang/services/trackbacks/3115.html</trackback:ping><description><![CDATA[<P><A href="http://www.blogjava.net/Files/jinfeng_wang/Hibernate%20Transactions%20Theory.zip">Hibernate Transaction Theory</A>&nbsp;released.<BR><BR>翻译节选于《Hibernate in Action》Chapter 5，本文未经原作者同意，其著作权为原作者所有，请勿任意转载。如有翻译问题，请与<A href="mailto:jinfeng_wang@msn.com">jinfeng_wang</A>联系。<BR><BR>下载地址： <A href="http://www.blogjava.net/Files/jinfeng_wang/Hibernate%20Transactions%20Theory.zip">http://www.blogjava.net/Files/jinfeng_wang/Hibernate%20Transactions%20Theory.zip</A></P><img src ="http://www.blogjava.net/jinfeng_wang/aggbug/3115.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jinfeng_wang/" target="_blank">jinfeng_wang</a> 2005-04-11 11:59 <a href="http://www.blogjava.net/jinfeng_wang/archive/2005/04/11/3115.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>hibernate transaction theory(2)</title><link>http://www.blogjava.net/jinfeng_wang/archive/2005/04/07/2945.html</link><dc:creator>jinfeng_wang</dc:creator><author>jinfeng_wang</author><pubDate>Thu, 07 Apr 2005 08:10:00 GMT</pubDate><guid>http://www.blogjava.net/jinfeng_wang/archive/2005/04/07/2945.html</guid><wfw:comment>http://www.blogjava.net/jinfeng_wang/comments/2945.html</wfw:comment><comments>http://www.blogjava.net/jinfeng_wang/archive/2005/04/07/2945.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/jinfeng_wang/comments/commentRss/2945.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jinfeng_wang/services/trackbacks/2945.html</trackback:ping><description><![CDATA[<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><B><I><SPAN lang=EN-US style="FONT-SIZE: 13pt; FONT-FAMILY: Arial; mso-font-kerning: 0pt">5.2 Working with application transactions</SPAN></I></B><SPAN lang=EN-US style="FONT-SIZE: 10pt; FONT-FAMILY: Arial; mso-font-kerning: 0pt"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></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="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">In our CaveatEmptor application, both the user who posted a comment and any system administrator can open an Edit Comment screen to delete or edit the text of a comment. Suppose two different administrators open the edit screen to view the same comment simultaneously. Both edit the comment text and submit their changes. At this point, we have three ways to handle the concurrent attempts to<o:p></o:p></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="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">write to the database:<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 6pt; FONT-FAMILY: ZapfDingbats; mso-font-kerning: 0pt">■ </SPAN><I><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">Last commit wins—</SPAN></I><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">Both updates succeed, and the second update overwrites the changes of the first. No error message is shown. <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 6pt; FONT-FAMILY: ZapfDingbats; mso-font-kerning: 0pt">■ </SPAN><I><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">First commit wins—</SPAN></I><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">The first modification is persisted, and the user submitting the second change receives an error message. The user must restart the business process by retrieving the updated comment. This option is often called <I>optimistic locking</I>.<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; TEXT-ALIGN: left; mso-list: l0 level1 lfo3; tab-stops: list 18.0pt; mso-layout-grid-align: none" align=left><SPAN lang=EN-US style="FONT-SIZE: 6pt; FONT-FAMILY: ZapfDingbats; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">■<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN><I><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">Merge conflicting updates—</SPAN></I><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">The first modification is persisted, and the second modification may be applied selectively by the user.<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在我们的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; mso-font-kerning: 0pt">CavertEmptor</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中，用户和系统管理员都可以打开“编辑</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; mso-font-kerning: 0pt">cooment</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">”功能，删除或者编辑评论。假设同时有两个管理员对同一个评论打开编辑功能，他们都对评论进行编辑然后提交。这是，我们发现可能有三种方式对此并发操作进行处理、写入数据库：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; mso-font-kerning: 0pt"><o:p></o:p></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-SIZE: 10pt; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">后者提交获胜－两次更新都成功，但是第二次更新将会覆盖第一次的更新，不显示任何错误。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; mso-font-kerning: 0pt"><o:p></o:p></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-SIZE: 10pt; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">前者提交获胜－第一个提交者成功，更新数据库，后一个提交失败，并返回错误信息。用户必须重新开始整个业务过程，取得被更新的评论。者就是常说的“乐观锁”。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; mso-font-kerning: 0pt"><o:p></o:p></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-SIZE: 10pt; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">合并更新冲突－第一个更新被保存，而第二个更新则由用户选择是否保存。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; mso-font-kerning: 0pt"><o:p></o:p></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-SIZE: 10pt; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN><o:p></o:p></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="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">The first option, last commit wins, is problematic; the second user overwrites the changes of the first user without seeing the changes made by the first user or even knowing that they existed. In our example, this probably wouldn’t matter, but it would be unacceptable for some other kinds of data. The second and third options are usually acceptable for most kinds of data. From our point of view, the third option is just a variation of the second—instead of showing an error message, we show the message and then allow the user to manually merge changes. There is no single best solution. You must investigate your own business requirements to decide among these three options.<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><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="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">&nbsp;<o:p></o:p></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="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">The first option happens by default if you don’t do anything special in your application</SPAN><SPAN style="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 lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">On the other hand, Hibernate can help you implement the second and third strategies, using <I>managed versioning </I>for <I>optimistic locking</I>.<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN style="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 lang=EN-US style="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: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">可以通过使用对“乐观锁”使用“管理版本”，帮助你实现第二个或第三个方案。</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">&nbsp;<o:p></o:p></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="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">Managed versioning relies on either a version number that is incremented or a timestamp that is updated to the current time, every time an object is modified. For Hibernate managed versioning, we must add a new property to our </SPAN><SPAN lang=EN-US style="FONT-SIZE: 9.5pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">Comment </SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">class and map it as a version number using the </SPAN><SPAN lang=EN-US style="FONT-SIZE: 9.5pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;version&gt; </SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">tag. First, let’s look at the changes to the </SPAN><SPAN lang=EN-US style="FONT-SIZE: 9.5pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">Comment </SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">class:<o:p></o:p></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-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">public class Comment {<o:p></o:p></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-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">...<o:p></o:p></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-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">private int version;<o:p></o:p></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-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">...<o:p></o:p></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-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">void setVersion(int version) {<o:p></o:p></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-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">this.version = version;<o:p></o:p></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-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">}<o:p></o:p></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-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">int getVersion() {<o:p></o:p></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-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">return version;<o:p></o:p></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-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">}<o:p></o:p></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-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="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 lang=EN-US style="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: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，我们必须给</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">Comment</SPAN><SPAN style="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 lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">&lt;version&gt;</SPAN><SPAN style="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 lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">Comment</SPAN><SPAN style="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 lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt"><o:p></o:p></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="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">public class Comment {<o:p></o:p></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="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">...<o:p></o:p></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="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">private int version;<o:p></o:p></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="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">...<o:p></o:p></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="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">void setVersion(int version) {<o:p></o:p></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="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">this.version = version;<o:p></o:p></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="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">}<o:p></o:p></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="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">int getVersion() {<o:p></o:p></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="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">return version;<o:p></o:p></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="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">}<o:p></o:p></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="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">}<o:p></o:p></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-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&nbsp;<o:p></o:p></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="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">You can also use a public scope for the setter and getter methods. The </SPAN><SPAN lang=EN-US style="FONT-SIZE: 9.5pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;version&gt; </SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">property mapping must come immediately after the identifier property mapping in the mapping file for the </SPAN><SPAN lang=EN-US style="FONT-SIZE: 9.5pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">Comment </SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">class:<o:p></o:p></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-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;class name="Comment" table="COMMENTS"&gt;<o:p></o:p></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-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;id ...<o:p></o:p></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-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;version name="version" column="VERSION"/&gt;<o:p></o:p></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-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">...<o:p></o:p></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-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;/&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Courier; mso-hansi-font-family: Courier">你可以使用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">public</SPAN><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Courier; mso-hansi-font-family: Courier">的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">setter</SPAN><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Courier; mso-hansi-font-family: Courier">或</SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">getter</SPAN><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Courier; mso-hansi-font-family: Courier">方法，这里的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;version&gt;</SPAN><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Courier; mso-hansi-font-family: Courier">映射的定义必须紧跟在映射文件中</SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">comment</SPAN><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Courier; mso-hansi-font-family: Courier">类的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">id</SPAN><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Courier; mso-hansi-font-family: Courier">后面。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt"><o:p></o:p></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-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;class name="Comment" table="COMMENTS"&gt;<o:p></o:p></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-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;id ...<o:p></o:p></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-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;version name="version" column="VERSION"/&gt;<o:p></o:p></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-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">...<o:p></o:p></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-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&lt;/&gt;<o:p></o:p></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-SIZE: 10pt; mso-font-kerning: 0pt">&nbsp;<o:p></o:p></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="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">You don’t need to set the value of the version or timestamp property yourself; Hibernate will initialize the value when you first save a </SPAN><SPAN lang=EN-US style="FONT-SIZE: 9.5pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">Comment</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">, and increment or reset it whenever the object is modified. Whenever Hibernate updates a comment, it uses the version column in the </SPAN><SPAN lang=EN-US style="FONT-SIZE: 9.5pt; mso-font-kerning: 0pt">SQL</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9.5pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">WHERE </SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">clause:<o:p></o:p></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="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">update COMMENTS set COMMENT_TEXT='New comment text', VERSION=3<o:p></o:p></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="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">where COMMENT_ID=123 and VERSION=2<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="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 lang=EN-US style="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: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">将会在你保存</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">Commment</SPAN><SPAN style="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 lang=EN-US style="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: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">何时更新</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">comment,</SPAN><SPAN style="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 lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">SQL</SPAN><SPAN style="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 lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">where</SPAN><SPAN style="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 lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">version</SPAN><SPAN style="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 lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt"><o:p></o:p></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="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">update COMMENTS set COMMENT_TEXT='New comment text', VERSION=3<o:p></o:p></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="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">where COMMENT_ID=123 and VERSION=2<o:p></o:p></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-SIZE: 8pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">&nbsp;<o:p></o:p></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="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">If another application transaction would have updated the same item since it was read by the current application transaction, the </SPAN><SPAN lang=EN-US style="FONT-SIZE: 9.5pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">VERSION </SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">column would not contain the value 2, and the row would not be updated. Hibernate would check the row count returned by the </SPAN><SPAN lang=EN-US style="FONT-SIZE: 9.5pt; mso-font-kerning: 0pt">JDBC </SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">driver—which in this case would be the number of rows updated, zero—and throw a </SPAN><SPAN lang=EN-US style="FONT-SIZE: 9.5pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">StaleObjectStateException</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">. Using this exception, we might show the user of the second application transaction an error message (“You have been working with stale data because another user modified it!”) and let the <I>first commit win</I>. Alternatively, we could catch the exception and show the second user a new screen, allowing the user to manually <I>merge changes </I>between the two versions.</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; mso-font-kerning: 0pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none" align=left><SPAN style="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 lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">2</SPAN><SPAN style="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 lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">3</SPAN><SPAN style="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 lang=EN-US style="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: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">将会检查</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">jdbc</SPAN><SPAN style="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 lang=EN-US style="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">0</SPAN><SPAN style="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 lang=EN-US style="FONT-SIZE: 9.5pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt">StaleObjectStateException</SPAN><SPAN style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-ascii-font-family: Courier; mso-hansi-font-family: Courier">异常。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9.5pt; FONT-FAMILY: Courier; mso-font-kerning: 0pt"><o:p></o:p></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="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">&nbsp;<o:p></o:p></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="mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">Using this exception, we might show the user of the second application transaction an error message (“You have been working with stale data because another user modified it!”) and let the <I>first commit win</I>. Alternatively, we could catch the exception and show the second user a new screen, allowing the user to manually <I>merge changes </I>between the two versions.</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; mso-font-kerning: 0pt"><o:p></o:p></SPAN></P><SPAN style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Courier; mso-hansi-font-family: Courier; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">使用此异常，就可以给第二个应用事务的用户显式错误信息（你正使用的数据已经被其他人更新了），让第一个</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">提交者获胜</SPAN><SPAN style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Courier; mso-hansi-font-family: Courier; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">。当然，你也可以捕捉异常，然后给第二个用户一个新的平面，允许它手工合并这两个版本的数据。</SPAN><img src ="http://www.blogjava.net/jinfeng_wang/aggbug/2945.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jinfeng_wang/" target="_blank">jinfeng_wang</a> 2005-04-07 16:10 <a href="http://www.blogjava.net/jinfeng_wang/archive/2005/04/07/2945.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>hibernate Transactions theory (1)</title><link>http://www.blogjava.net/jinfeng_wang/archive/2005/04/07/2916.html</link><dc:creator>jinfeng_wang</dc:creator><author>jinfeng_wang</author><pubDate>Thu, 07 Apr 2005 06:03:00 GMT</pubDate><guid>http://www.blogjava.net/jinfeng_wang/archive/2005/04/07/2916.html</guid><wfw:comment>http://www.blogjava.net/jinfeng_wang/comments/2916.html</wfw:comment><comments>http://www.blogjava.net/jinfeng_wang/archive/2005/04/07/2916.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jinfeng_wang/comments/commentRss/2916.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jinfeng_wang/services/trackbacks/2916.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: &nbsp;5.1.4 理解事务隔离级别&nbsp;问题The ANSI SQL standard defines the standard transaction isolation levels in terms of which of these phenomena are permissible:ANSI SQL分别针对以下可能出现的问题，定义了不同的标准事务隔离级别。...&nbsp;&nbsp;<a href='http://www.blogjava.net/jinfeng_wang/archive/2005/04/07/2916.html'>阅读全文</a><img src ="http://www.blogjava.net/jinfeng_wang/aggbug/2916.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jinfeng_wang/" target="_blank">jinfeng_wang</a> 2005-04-07 14:03 <a href="http://www.blogjava.net/jinfeng_wang/archive/2005/04/07/2916.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>hibernate's session和《企业应用架构模式》第11章</title><link>http://www.blogjava.net/jinfeng_wang/archive/2005/04/05/2869.html</link><dc:creator>jinfeng_wang</dc:creator><author>jinfeng_wang</author><pubDate>Tue, 05 Apr 2005 03:13:00 GMT</pubDate><guid>http://www.blogjava.net/jinfeng_wang/archive/2005/04/05/2869.html</guid><wfw:comment>http://www.blogjava.net/jinfeng_wang/comments/2869.html</wfw:comment><comments>http://www.blogjava.net/jinfeng_wang/archive/2005/04/05/2869.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jinfeng_wang/comments/commentRss/2869.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jinfeng_wang/services/trackbacks/2869.html</trackback:ping><description><![CDATA[<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><B><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-fareast-language: ZH-CN">hibernate实现了《企业应用架构模式》第11章的许多模式，结合起来则更能理解hibernate的session的作用。只是双方的一些术语未必能直接对应上。<BR>＝＝＝＝＝＝＝＝＝＝＝<BR>Session接口<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-fareast-language: ZH-CN">Session（会话）接口是Hibernate应用使用的主要接口。会话接口的实例是轻量级的并且创建与销毁的代价也不昂贵。这很重要因为你的应用可能始终在创建与销毁会话，可能每一次请求都会如此。Hibernate会话并不是线程安全的因此应该被设计为每次只能在一个线程中使用。<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-fareast-language: ZH-CN">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-fareast-language: ZH-CN">Hibernate会话是一个介于连接和事务之间的概念。<FONT color=#ff1493>你可以简单地认为会话是对于一个单独的工作单元已装载对象的缓存或集合。Hibernate可以检测到这个工作单元中对象的改变。</FONT>我们有时也将会话称为持续性管理器，因为它也是与持续性有关的操作例如存储和取出对象的接口。注意，Hibernate会话与Web层的HttpSession没有任何关系。当我们在本书中使用会话时，我们指的是Hibernate会话。为了区别，有时我们将HttpSession对象称为用户会话。<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-fareast-language: ZH-CN">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-fareast-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><B><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">SessionFactory</SPAN></B><B><SPAN style="FONT-FAMILY: 宋体; mso-fareast-language: ZH-CN; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">接口</SPAN></B><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-fareast-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN style="FONT-FAMILY: 宋体; mso-fareast-language: ZH-CN">应用从</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-bidi-font-size: 9.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">SessionFactory</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-fareast-language: ZH-CN; mso-bidi-font-size: 9.5pt; mso-bidi-font-family: Arial; mso-font-kerning: 0pt">（会话工厂）里获得会话实例。与会话接口相比，这个对象不够令人兴奋。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-fareast-language: ZH-CN"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-fareast-language: ZH-CN">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN style="FONT-FAMILY: 宋体; mso-fareast-language: ZH-CN">会话工厂当然不是轻量级的！它打算在多个应用线程间进行共享。典型地，<FONT color=#ff1493>整个应用只有唯一的一个会话工厂——例如在应用初始化时被创建。然而，如果你的应用使用<SPAN lang=EN-US>Hibernate访问多个数据库，你需要对每一个数据库使用一个会话工厂。<o:p></o:p></SPAN></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN lang=EN-US style="FONT-FAMILY: 宋体; mso-fareast-language: ZH-CN">&nbsp;<o:p></o:p></SPAN></P><SPAN style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-fareast-language: ZH-CN; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-bidi-language: AR-SA">会话工厂缓存了生成的<SPAN lang=EN-US>SQL语句和Hibernate在运行时使用的映射元数据。它也保存了在一个工作单元中读入的数据并且可能在以后的工作单元中被重用（只有类和集合映射指定了这种二级缓存是想要的时才会如此）。<BR><BR><BR></SPAN></SPAN><img src ="http://www.blogjava.net/jinfeng_wang/aggbug/2869.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jinfeng_wang/" target="_blank">jinfeng_wang</a> 2005-04-05 11:13 <a href="http://www.blogjava.net/jinfeng_wang/archive/2005/04/05/2869.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>hibernate's casade table.</title><link>http://www.blogjava.net/jinfeng_wang/archive/2005/04/03/2798.html</link><dc:creator>jinfeng_wang</dc:creator><author>jinfeng_wang</author><pubDate>Sun, 03 Apr 2005 13:43:00 GMT</pubDate><guid>http://www.blogjava.net/jinfeng_wang/archive/2005/04/03/2798.html</guid><wfw:comment>http://www.blogjava.net/jinfeng_wang/comments/2798.html</wfw:comment><comments>http://www.blogjava.net/jinfeng_wang/archive/2005/04/03/2798.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jinfeng_wang/comments/commentRss/2798.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jinfeng_wang/services/trackbacks/2798.html</trackback:ping><description><![CDATA[<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN style="COLOR: blue; mso-ansi-language: EN">&nbsp;</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;?</SPAN><SPAN style="COLOR: #ff00ff">xml&nbsp;version="1.0"</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: #ff00ff">DOCTYPE&nbsp;hibernate-mapping&nbsp;PUBLIC&nbsp;"-//Hibernate/Hibernate&nbsp;Mapping&nbsp;DTD&nbsp;2.0//EN"<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><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><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">="com.oreilly.hh.Album"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;table</SPAN><SPAN style="COLOR: #0000ff">="ALBUM"</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">meta&nbsp;</SPAN><SPAN style="COLOR: #ff0000">attribute</SPAN><SPAN style="COLOR: #0000ff">="class-description"</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;Represents&nbsp;an&nbsp;album&nbsp;in&nbsp;the&nbsp;music&nbsp;database,&nbsp;an&nbsp;organized&nbsp;list&nbsp;of&nbsp;tracks.<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@author&nbsp;Jim&nbsp;Elliott&nbsp;(with&nbsp;help&nbsp;from&nbsp;Hibernate)<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">meta</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><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">="int"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;column</SPAN><SPAN style="COLOR: #0000ff">="ALBUM_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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">meta&nbsp;</SPAN><SPAN style="COLOR: #ff0000">attribute</SPAN><SPAN style="COLOR: #0000ff">="scope-set"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">protected</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">meta</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">generator&nbsp;</SPAN><SPAN style="COLOR: #ff0000">class</SPAN><SPAN style="COLOR: #0000ff">="native"</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</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><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">property&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="title"</SPAN><SPAN style="COLOR: #ff0000">&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">meta&nbsp;</SPAN><SPAN style="COLOR: #ff0000">attribute</SPAN><SPAN style="COLOR: #0000ff">="use-in-tostring"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">true</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">meta</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">column&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="TITLE"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;not-null</SPAN><SPAN style="COLOR: #0000ff">="true"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;index</SPAN><SPAN style="COLOR: #0000ff">="ALBUM_TITLE"</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">property</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><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">property&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="numDiscs"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;type</SPAN><SPAN style="COLOR: #0000ff">="integer"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;not-null</SPAN><SPAN style="COLOR: #0000ff">="true"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><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">set&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="artists"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;table</SPAN><SPAN style="COLOR: #0000ff">="ALBUM_ARTISTS"</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">="ALBUM_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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">many-to-many&nbsp;</SPAN><SPAN style="COLOR: #ff0000">class</SPAN><SPAN style="COLOR: #0000ff">="com.oreilly.hh.Artist"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;column</SPAN><SPAN style="COLOR: #0000ff">="ARTIST_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;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">set</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><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">set&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="comments"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;table</SPAN><SPAN style="COLOR: #0000ff">="ALBUM_COMMENTS"</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">="ALBUM_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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">element&nbsp;</SPAN><SPAN style="COLOR: #ff0000">column</SPAN><SPAN style="COLOR: #0000ff">="COMMENT"</SPAN><SPAN style="COLOR: #ff0000">&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;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">set</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><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">list&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="tracks"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;table</SPAN><SPAN style="COLOR: #0000ff">="ALBUM_TRACKS"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;cascade</SPAN><SPAN style="COLOR: #0000ff">="all"</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">meta&nbsp;</SPAN><SPAN style="COLOR: #ff0000">attribute</SPAN><SPAN style="COLOR: #0000ff">="use-in-tostring"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">true</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">meta</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">="ALBUM_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;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">index&nbsp;</SPAN><SPAN style="COLOR: #ff0000">column</SPAN><SPAN style="COLOR: #0000ff">="POS"</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">composite-element&nbsp;</SPAN><SPAN style="COLOR: #ff0000">class</SPAN><SPAN style="COLOR: #0000ff">="com.oreilly.hh.AlbumTrack"</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&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="track"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;class</SPAN><SPAN style="COLOR: #0000ff">="com.oreilly.hh.Track"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;cascade</SPAN><SPAN style="COLOR: #0000ff">="all"</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;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">meta&nbsp;</SPAN><SPAN style="COLOR: #ff0000">attribute</SPAN><SPAN style="COLOR: #0000ff">="use-in-tostring"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">true</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">meta</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;&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">="TRACK_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">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;&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">="disc"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;type</SPAN><SPAN style="COLOR: #0000ff">="integer"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;not-null</SPAN><SPAN style="COLOR: #0000ff">="true"</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">="positionOnDisc"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;type</SPAN><SPAN style="COLOR: #0000ff">="integer"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;not-null</SPAN><SPAN style="COLOR: #0000ff">="true"</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">composite-element</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">list</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><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">property&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="added"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;type</SPAN><SPAN style="COLOR: #0000ff">="date"</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">meta&nbsp;</SPAN><SPAN style="COLOR: #ff0000">attribute</SPAN><SPAN style="COLOR: #0000ff">="field-description"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">When&nbsp;the&nbsp;album&nbsp;was&nbsp;created</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">meta</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">property</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><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><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></DIV></DIV><BR>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><BR>&nbsp;</P>
<P class=doctext style="MARGIN: auto 0cm"><SPAN lang=EN-US>The </SPAN><FONT size=3><FONT face="Times New Roman"><TT><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">cascade</SPAN></TT><SPAN lang=EN-US> attribute tells Hibernate that you want operations performed on a 'parent' object to be transitively applied to its 'child' or 'dependent' objects. It's applicable to all forms of collections and associations. There are several possible values to choose among. The most common are </SPAN><TT><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">none</SPAN></TT><SPAN lang=EN-US> (the default), </SPAN><TT><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">save-update, delete</SPAN></TT><SPAN lang=EN-US>, and </SPAN><TT><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">all</SPAN></TT><SPAN lang=EN-US> (which combines </SPAN><TT><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">save-update</SPAN></TT><SPAN lang=EN-US> and </SPAN><TT><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">delete</SPAN></TT><SPAN lang=EN-US>). You can also change the default from </SPAN><TT><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">none</SPAN></TT><SPAN lang=EN-US> to </SPAN><TT><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">save-update</SPAN></TT><SPAN lang=EN-US> throughout your entire mapping document by supplying a </SPAN><TT><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">default-cascade</SPAN></TT><SPAN lang=EN-US> attribute in the </SPAN><TT><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">hibernate-mapping</SPAN></TT><SPAN lang=EN-US> tag itself.<BR></SPAN></FONT></FONT></P>
<P class=doctext style="MARGIN: auto 0cm"><SPAN lang=EN-US>级联（cascade）属性告诉hibernate：所有对父对象的操作都将付诸于子对象和依赖对象上。级联可以应用于各种形式的集合和关联中。这里级联的具体取值可以有多个，最常用的有：none(默认值)，save-update,delete和all（其中包含了save-update和delete）。你可以在hibernate-mappiong tag中通过设置default-casade属性，修改这里的casade的默认值，例如修改其默认值为save-update。<BR><BR>In our example, we want the tracks owned by an album to be automatically managed by the album, so that when we delete the album, its tracks are deleted. Note that we need to apply the </SPAN><FONT size=3><FONT face="Times New Roman"><TT><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">cascade</SPAN></TT><SPAN lang=EN-US> attribute both to the </SPAN><TT><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">tracks</SPAN></TT><SPAN lang=EN-US> collection and its constituent </SPAN><TT><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">track</SPAN></TT><SPAN lang=EN-US> element to achieve this. Also, by using a </SPAN><TT><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">cascade</SPAN></TT><SPAN lang=EN-US> value of </SPAN><TT><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">all</SPAN></TT><SPAN lang=EN-US>, we eliminate the need to explicitly save any </SPAN><TT><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">Track</SPAN></TT><SPAN lang=EN-US> objects we create for the album—the </SPAN><TT><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'">addAlbumTrack()</SPAN></TT><SPAN lang=EN-US> method of <A href="http://www.blogjava.net/jinfeng_wang/admin/hibernate-CHP-5-SECT-3.html#hibernate-CHP-5-EXAMPLE-7">Example 5-7</A> no longer needs the line:<BR><BR>&nbsp;&nbsp; session.save(track);<BR><BR>在我们的例子中，我们希望track完全由album自动掌管，当我们删除album时，它的track也会被删除。注意，这里我们需要在两处设置casade属性实现此任务：tracks集合和它的组成元素track。同样，由于我们讲casade设置为all，那么不再需要显式的保存为album创建的track对象，5-7例子中的addAlbumTrack方法不再需要调用session.save(track)方法。<BR><BR></SPAN></FONT></FONT></P>
<P class=doctext style="MARGIN: auto 0cm"><SPAN lang=EN-US>By telling Hibernate that it's fully responsible for the relationship between an album and its track, we enable it to persist tracks when they're added to the album as well as delete them when the album itself is deleted.<BR><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P><FONT size=3><SPAN lang=EN-US style="FONT-SIZE: 10.5pt; FONT-FAMILY: 'Times New Roman'; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 1.0pt; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA"><BR>通过高知hibernate，由其完全负责album和track直接的关系，可以保证track在加入到album时自动保存，在album删除时自动删除。<BR><BR>Delegating this sort of bookkeeping to the mapping layer can be very convenient, freeing you to focus on more abstract and important tasks, so it is worth using when appropriate. It's reminiscent of the liberation provided by Java's pervasive garbage collection, but it can't be as comprehensive because there is no definitive way to know when you're finished with persistent data by performing reachability analysis; you need to indicate it by calling </SPAN><FONT face="Times New Roman"><TT><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-font-kerning: 1.0pt; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">delete()</SPAN></TT><SPAN lang=EN-US style="FONT-SIZE: 10.5pt; FONT-FAMILY: 'Times New Roman'; mso-ansi-language: EN-US; mso-bidi-font-size: 12.0pt; mso-fareast-font-family: 宋体; mso-font-kerning: 1.0pt; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA"> and establishing lifecycle connections. The trade-off between flexibility and simple automation is yours to make, based on the nature of your data and the needs of your project.<BR>将这样的任务完全交代给持久层使得我们的任务更加的简便，可以让我们将注意力投注于更抽象更重要的业务，因此恰当的使用casade是值得的，这就像java的垃圾收集一样，使我们的工作得到了一定的解放。但是，由于目前并没有任何的可达性分析方法，可以确切的知道“你是否已经不再需要此持久层数据”，因此你必须调用delete()方法，才能建立起此生命周期链接。你必须依据你的数据的特点和项目的需要，在灵活性和自动化的简单性进行权衡。<BR><BR><FONT size=3>For example, if you use <TT>Collections</TT> methods to remove a <TT>Track</TT> from an <TT>Album's tracks</TT> property, this breaks the link between the <TT>Album</TT> and <TT>Track</TT> but does <SPAN class=docEmphasis>not</SPAN> actually delete the <TT>Track</TT> record. Even if you later delete the entire <TT>Album</TT>, this <TT>Track</TT> will remain, because it wasn't linked to the <TT>Album</TT> at the time that it was deleted. <BR>例如：如果你使用Album的tracks collection的remove方法，删除一个track，这将会移除album和track直接的链接，但是它并没真正的删除track记录。即使你后来整个的删除album，这个track也将会继续保留着，因为此时该track已经和album失去了链接。<BR>//（ 译者注）这里的含义是：级联是有范围的，表ALBUM和表TRACK之间通过表Album_Tracks建立了联系。在albu.hbm.xml中，进行了级联配置，使得Album和ALBUM_TRACKS之间级联。当删除某个album时，那么相应的ALBUM_TRACKS中的记录也将删除。如果对album中的tracks执行remove方法时，那么ALBUM_TRACKS中的相应记录也将删除。但是这里的级联却无法延伸到表TRACK中，TRACK表中的记录将安然无恙，依然存在。<BR>//原文中的tracks出现在两处，一个是Album对象的属性，其对应着ALBUM_TRACKS的记录。一个则是单独的TRACK表，所以表述十分容易引起混淆。</FONT></SPAN></FONT></FONT><img src ="http://www.blogjava.net/jinfeng_wang/aggbug/2798.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jinfeng_wang/" target="_blank">jinfeng_wang</a> 2005-04-03 21:43 <a href="http://www.blogjava.net/jinfeng_wang/archive/2005/04/03/2798.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>hibernate's transient object and persistent object</title><link>http://www.blogjava.net/jinfeng_wang/archive/2005/04/01/2706.html</link><dc:creator>jinfeng_wang</dc:creator><author>jinfeng_wang</author><pubDate>Fri, 01 Apr 2005 06:21:00 GMT</pubDate><guid>http://www.blogjava.net/jinfeng_wang/archive/2005/04/01/2706.html</guid><wfw:comment>http://www.blogjava.net/jinfeng_wang/comments/2706.html</wfw:comment><comments>http://www.blogjava.net/jinfeng_wang/archive/2005/04/01/2706.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jinfeng_wang/comments/commentRss/2706.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jinfeng_wang/services/trackbacks/2706.html</trackback:ping><description><![CDATA[<P class=docText></P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">package&nbsp;com.oreilly.hh;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>import&nbsp;net.sf.hibernate.</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>import&nbsp;net.sf.hibernate.cfg.Configuration;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>import&nbsp;java.sql.Time;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>import&nbsp;java.util.Date;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG id=Codehighlighter1_142_208_Open_Image onclick="this.style.display='none'; Codehighlighter1_142_208_Open_Text.style.display='none'; Codehighlighter1_142_208_Closed_Image.style.display='inline'; Codehighlighter1_142_208_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_142_208_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_142_208_Closed_Text.style.display='none'; Codehighlighter1_142_208_Open_Image.style.display='inline'; Codehighlighter1_142_208_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN id=Codehighlighter1_142_208_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</SPAN><SPAN id=Codehighlighter1_142_208_Open_Text><SPAN style="COLOR: #008000">/*</SPAN><SPAN style="COLOR: #008000">*<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;*&nbsp;Create&nbsp;sample&nbsp;data,&nbsp;letting&nbsp;Hibernate&nbsp;persist&nbsp;it&nbsp;for&nbsp;us.<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;</SPAN><SPAN style="COLOR: #008000">*/</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_234_2291_Open_Image onclick="this.style.display='none'; Codehighlighter1_234_2291_Open_Text.style.display='none'; Codehighlighter1_234_2291_Closed_Image.style.display='inline'; Codehighlighter1_234_2291_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_234_2291_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_234_2291_Closed_Text.style.display='none'; Codehighlighter1_234_2291_Open_Image.style.display='inline'; Codehighlighter1_234_2291_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">&nbsp;CreateTest&nbsp;</SPAN><SPAN id=Codehighlighter1_234_2291_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_234_2291_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG id=Codehighlighter1_297_2289_Open_Image onclick="this.style.display='none'; Codehighlighter1_297_2289_Open_Text.style.display='none'; Codehighlighter1_297_2289_Closed_Image.style.display='inline'; Codehighlighter1_297_2289_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_297_2289_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_297_2289_Closed_Text.style.display='none'; Codehighlighter1_297_2289_Open_Image.style.display='inline'; Codehighlighter1_297_2289_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;main(String&nbsp;args[])&nbsp;throws&nbsp;Exception&nbsp;</SPAN><SPAN id=Codehighlighter1_297_2289_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_297_2289_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;Create&nbsp;a&nbsp;configuration&nbsp;based&nbsp;on&nbsp;the&nbsp;properties&nbsp;file&nbsp;we've&nbsp;put<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;in&nbsp;the&nbsp;standard&nbsp;place.</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Configuration&nbsp;config&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Configuration();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;Tell&nbsp;it&nbsp;about&nbsp;the&nbsp;classes&nbsp;we&nbsp;want&nbsp;mapped,&nbsp;taking&nbsp;advantage&nbsp;of<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;the&nbsp;way&nbsp;we've&nbsp;named&nbsp;their&nbsp;mapping&nbsp;documents.</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;config.addClass(Track.</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;Get&nbsp;the&nbsp;session&nbsp;factory&nbsp;we&nbsp;can&nbsp;use&nbsp;for&nbsp;persistence</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SessionFactory&nbsp;sessionFactory&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;config.buildSessionFactory();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;Ask&nbsp;for&nbsp;a&nbsp;session&nbsp;using&nbsp;the&nbsp;JDBC&nbsp;information&nbsp;we've&nbsp;configured</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Session&nbsp;session&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;sessionFactory.openSession();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Transaction&nbsp;tx&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">;<BR><IMG id=Codehighlighter1_932_1919_Open_Image onclick="this.style.display='none'; Codehighlighter1_932_1919_Open_Text.style.display='none'; Codehighlighter1_932_1919_Closed_Image.style.display='inline'; Codehighlighter1_932_1919_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_932_1919_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_932_1919_Closed_Text.style.display='none'; Codehighlighter1_932_1919_Open_Image.style.display='inline'; Codehighlighter1_932_1919_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">try</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN id=Codehighlighter1_932_1919_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_932_1919_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;Create&nbsp;some&nbsp;data&nbsp;and&nbsp;persist&nbsp;it</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tx&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;session.beginTransaction();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Track&nbsp;track&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Track(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Russian&nbsp;Trance</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">vol2/album610/track02.mp3</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Time.valueOf(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">00:03:30</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">),&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Date(),<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(</SPAN><SPAN style="COLOR: #0000ff">short</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;session.save(track);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;track&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Track(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Video&nbsp;Killed&nbsp;the&nbsp;Radio&nbsp;Star</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">vol2/album611/track12.mp3</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Time.valueOf(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">00:03:49</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">),&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Date(),<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(</SPAN><SPAN style="COLOR: #0000ff">short</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;session.save(track);&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;track&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Track(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Gravity's&nbsp;Angel</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">vol2/album175/track03.mp3</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Time.valueOf(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">00:06:06</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">),&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Date(),<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(</SPAN><SPAN style="COLOR: #0000ff">short</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;session.save(track);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;We're&nbsp;done;&nbsp;make&nbsp;our&nbsp;changes&nbsp;permanent</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tx.commit();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG id=Codehighlighter1_1941_2116_Open_Image onclick="this.style.display='none'; Codehighlighter1_1941_2116_Open_Text.style.display='none'; Codehighlighter1_1941_2116_Closed_Image.style.display='inline'; Codehighlighter1_1941_2116_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_1941_2116_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1941_2116_Closed_Text.style.display='none'; Codehighlighter1_1941_2116_Open_Image.style.display='inline'; Codehighlighter1_1941_2116_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/