﻿<?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-Duran's technical life-随笔分类-技术积累</title><link>http://www.blogjava.net/sakis/category/1414.html</link><description>踏踏实实学技术，认认真真做研究。</description><language>zh-cn</language><lastBuildDate>Thu, 01 Mar 2007 19:32:10 GMT</lastBuildDate><pubDate>Thu, 01 Mar 2007 19:32:10 GMT</pubDate><ttl>60</ttl><item><title>关于MySql5的“data too long for column”错误</title><link>http://www.blogjava.net/sakis/archive/2006/07/14/58242.html</link><dc:creator>Duran's technical life</dc:creator><author>Duran's technical life</author><pubDate>Fri, 14 Jul 2006 11:12:00 GMT</pubDate><guid>http://www.blogjava.net/sakis/archive/2006/07/14/58242.html</guid><wfw:comment>http://www.blogjava.net/sakis/comments/58242.html</wfw:comment><comments>http://www.blogjava.net/sakis/archive/2006/07/14/58242.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/sakis/comments/commentRss/58242.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/sakis/services/trackbacks/58242.html</trackback:ping><description><![CDATA[从MySql5中运行本地脚本创建数据库，当插入中文字段时发生“data too long for column”错误。上网一查，发现多字节用户大都碰到了这种情况。google搜索网上的解决方法大都是要将数据库的编码方式为GBK或UTF8，可我在安装MySql时就选择了UTF8格式。原来错误原因是本地的脚本文件不是UTF8编码的，用记事本或UltraEdit将编码转为UTF8后问题解决。再次强调，JSP页面，数据库联接接方式，数据库创建，…，都须一致使用UTF8编码！<br /><br />BTW，MySql最近借着Web2.0的浪潮风头很劲啊，techn orati（好像这几天被GFW filter了），flickr，del.icio.us等一批网站都是用了MySql。MySql还专门在首页开了一大块来炫耀。<img src ="http://www.blogjava.net/sakis/aggbug/58242.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/sakis/" target="_blank">Duran's technical life</a> 2006-07-14 19:12 <a href="http://www.blogjava.net/sakis/archive/2006/07/14/58242.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Swing, Eclipse3.2 and Mattise4Eclipse</title><link>http://www.blogjava.net/sakis/archive/2006/07/13/58063.html</link><dc:creator>Duran's technical life</dc:creator><author>Duran's technical life</author><pubDate>Thu, 13 Jul 2006 14:17:00 GMT</pubDate><guid>http://www.blogjava.net/sakis/archive/2006/07/13/58063.html</guid><wfw:comment>http://www.blogjava.net/sakis/comments/58063.html</wfw:comment><comments>http://www.blogjava.net/sakis/archive/2006/07/13/58063.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/sakis/comments/commentRss/58063.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/sakis/services/trackbacks/58063.html</trackback:ping><description><![CDATA[
		<font size="2">Installed </font>
		<a href="http://java.sun.com/javase/6/download.jsp">
				<font size="2">JDK6</font>
		</a>
		<font size="2"> (Mustang) beta and </font>
		<a href="http://www.eclipse.org/downloads/">
				<font size="2">Eclipse3.2</font>
		</a>
		<font size="2">. As </font>
		<a href="http://java.sun.com/developer/technicalArticles/J2SE/Desktop/mustang/beta2.html">
				<font size="2">Sun promised</font>
		</a>
		<font size="2">, Swing library, especially the WindowsLookAndFeel feels much better. It’s hard to tell the difference between a Swing drawn window and a WINXP native window. Developing Java desktop applications is worth considering. Mattise, a free easy-to-use WYSIWYG Swing UI designer, is the only reason for many to use the tedious NetBeans. Recently, </font>
		<a href="http://www.genuitec.com/">
				<font size="2">Genuitec</font>
		</a>
		<font size="2"> provided Matisse4Eclipse, which is an implementation of Matisse that integrates its functionality into MyEclipse Workbench to enable the easy creation of Swing applications with Eclipse. So the only reason to use NetBeans has gone. </font>
<img src ="http://www.blogjava.net/sakis/aggbug/58063.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/sakis/" target="_blank">Duran's technical life</a> 2006-07-13 22:17 <a href="http://www.blogjava.net/sakis/archive/2006/07/13/58063.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[笔记]事务处理</title><link>http://www.blogjava.net/sakis/archive/2005/09/09/12532.html</link><dc:creator>Duran's technical life</dc:creator><author>Duran's technical life</author><pubDate>Fri, 09 Sep 2005 05:09:00 GMT</pubDate><guid>http://www.blogjava.net/sakis/archive/2005/09/09/12532.html</guid><wfw:comment>http://www.blogjava.net/sakis/comments/12532.html</wfw:comment><comments>http://www.blogjava.net/sakis/archive/2005/09/09/12532.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/sakis/comments/commentRss/12532.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/sakis/services/trackbacks/12532.html</trackback:ping><description><![CDATA[<P><FONT face="Courier New" size=2>@title [笔记]事务处理</FONT></P>
<P><FONT face="Courier New" size=2>#1 Transaction Propagation Behavior<BR>Required:Excute within a current tx, create a new one if none exists.<BR>Supports: Excute within a current tx, execute without a tx if none exsits.<BR>Mandatory: Excute within a current tx, throw an exception if none exists.<BR>Requires New: Create a new tx and excute within the tx, suspend the current tx if one exists.<BR>Not Supported: Excute without a tx, suspend the current tx if none exsits.<BR>Never: Excute without a tx, throw an exception if a tx exsits.</FONT></P>
<P><FONT face="Courier New" size=2>#2 Transaction Isolation Level[1]<BR>#2.1 Concurrent Problem<BR>Dirty Reads: 脏读（脏数据指已更新，还没提交的数据）。事务T1读取到事务T2中的脏数据。</FONT></P>
<P><FONT face="Courier New" size=2>Unrepeatable Reads: 不可重复读。事务T1检索到某行后，事务T2更新并提交了该行，若事务T2再次检索该行，则会看到不一样的结果。</FONT></P>
<P><FONT face="Courier New" size=2>Phantom Reads: 虚读。事务T1检索到符合某条件的行集后，事务T2插入并提交了满足该条件的新行，若事务T2再次按该条件检索，则会看到以前不存在的行“Phantom”。</FONT></P>
<P><FONT face="Courier New" size=2>#2.2 Isolation Level<BR>+---------------+-------+------------------+-----------+<BR>|Isolation Level|Phantom|Unrepeatable Reads|Dirty Reads|<BR>+---------------+-------+------------------+-----------+<BR>|Read Uncommited|&nbsp;&nbsp; Y&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Y&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp; Y&nbsp;&nbsp;&nbsp;&nbsp; |<BR>+---------------+-------+------------------+-----------+<BR>|Read Commited&nbsp; |&nbsp;&nbsp; Y&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Y&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp; N&nbsp;&nbsp;&nbsp;&nbsp; |<BR>+---------------+-------+------------------+-----------+<BR>|Repeatable Read|&nbsp;&nbsp; Y&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; N&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp; N&nbsp;&nbsp;&nbsp;&nbsp; |<BR>+---------------+-------+------------------+-----------+<BR>|Serializable&nbsp;&nbsp; |&nbsp;&nbsp; N&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; N&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp; N&nbsp;&nbsp;&nbsp;&nbsp; |<BR>+---------------+-------+------------------+-----------+</FONT></P>
<P><FONT face="Courier New" size=2>#3 Timeout</FONT></P>
<P><FONT face="Courier New" size=2>#4 ReadOnly Transaction<BR>只读事务保证了多条查询SQL的在事务级别的读一致性。JDBC和数据库会对只读事务做一些优化。</FONT></P>
<P><FONT face="Courier New" size=2>[1] C.J.Date, An Introduction to Database Systems 7th.</FONT></P><img src ="http://www.blogjava.net/sakis/aggbug/12532.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/sakis/" target="_blank">Duran's technical life</a> 2005-09-09 13:09 <a href="http://www.blogjava.net/sakis/archive/2005/09/09/12532.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>iteration::two Cairngorm 0.99 开发指南</title><link>http://www.blogjava.net/sakis/archive/2005/09/07/12342.html</link><dc:creator>Duran's technical life</dc:creator><author>Duran's technical life</author><pubDate>Wed, 07 Sep 2005 13:49:00 GMT</pubDate><guid>http://www.blogjava.net/sakis/archive/2005/09/07/12342.html</guid><wfw:comment>http://www.blogjava.net/sakis/comments/12342.html</wfw:comment><comments>http://www.blogjava.net/sakis/archive/2005/09/07/12342.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/sakis/comments/commentRss/12342.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/sakis/services/trackbacks/12342.html</trackback:ping><description><![CDATA[<P><FONT face="Courier New" size=2>iteration::two Cairngorm 0.99 开发指南<BR>@author <A href="mailto:notifyAll@hotmail.com">sakis</A><BR>@version 0.1</FONT></P>
<P><FONT face="Courier New" size=2>#0<BR>MXML优点：使用方便，XML代码简洁易懂<BR>缺点：事件、函数、界面描混在一起。程序规模大了难于开发维护。</FONT></P>
<P><FONT face="Courier New" size=2>#1<BR>Cairngorm框架是iterationtwo推出的号称基于JEE Best Practice的Flex程序开发的light-weight framework。(恩,light-weight这个词还真是流行呢)。目前最新版本为0.99。</FONT></P>
<P><FONT face="Courier New" size=2>Cairngorm的结构如下：<BR>org<BR>└─nevis<BR>&nbsp;&nbsp;&nbsp; └─cairngorm<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ├─application<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; │&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CairngormApplication.as<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; │<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ├─business<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; │&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Responder.as<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; │&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ServiceLocator.as<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; │<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ├─commands<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; │&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Command.as<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; │&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SequenceCommand.as<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; │<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ├─control<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; │&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Event.as<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; │&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EventBroadcaster.as<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; │&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FrontController.as<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; │<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ├─model<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; │&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ModelLocator.as<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; │<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ├─view<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; │&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ViewHelper.as<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; │&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ViewLocator.as<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; │<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; └─vo<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ValueObject.as</FONT></P>
<P><BR><FONT face="Courier New" size=2>#2<BR>下面给大家简单介绍Cairngorm的实现思路。</FONT></P>
<P><FONT face="Courier New" size=2>#2.1<BR>Command/FrontController将Event与Viwe分离。<BR>FrontController实现Singleton模式(以下简写为SP)。所有自定义的Command在要在FrontController构造函数中实例化并以关联数组的方式注册FrontController#addCommand(eventType:String, commandInstance:Command)。EventBroadcaster实现SP。Event类的结构为{type:eventType, data:eventData}。我们通过EventBroadcaster#broadcastEvent(eventType:String, eventData:Object)发布Event。Event发布后,与eventType对应的command instance执行Command#execute(event:Event)。</FONT></P>
<P><FONT face="Courier New" size=2>BTW：在Cairngorm的源码中，eventType、commandName、eventName混用，我统一用eventType。</FONT></P>
<P><FONT face="Courier New" size=2>#2.2<BR>ServiceLocator将Remote Service声明与View分离。<BR>ServiceLocator实现SP。在Cairngorm的demo中，又通过Delegate对象解除Command/Responder和ServiceLocator之间的依赖。这个Delegate做的事情其实意义不大，就是调用ServiceLocator中的Method，设置莫个Responder为相应远程方法的handler。个人觉得无谓地增加了代码量，而且Delegate对象也没实现SP，也就是说我们每次调用一次Remote Service中的Method，都要new一个Delegate对象，实在浪费。</FONT></P>
<P><FONT face="Courier New" size=2>#2.3<BR>ViewLocator/ViewHelper将View（MXML）中夹杂的function与View分离。<BR>ViewHelper有点意思，当一个ViewHelper在某个MXML页面中声明时，如&lt;view:LoginViewHelper id="loginViewHelper" /&gt;<?xml:namespace prefix = view /><view:LoginViewHelper id=loginViewHelper></view:LoginViewHelper>。ViewHelper能自动取得所在MXML对象的引用，并通过ViewLocator#register(id, this:ViewHelper)将自身注册到ViewLocator中。ViewLocator实现SP。借助ViewLocator/ViewHelper,我们就可以方便的调用不同MXML页面中的方法。</FONT></P>
<P><FONT face="Courier New" size=2>#2.4<BR>ModelLocator是一个marker interface，程序中Model可以放在某个ModelLocator方便调用。</FONT></P>
<P><FONT face="Courier New" size=2>#2.5<BR>ValueObject也是一个marker interface, 基本不需要。</FONT></P>
<P><FONT face="Courier New" size=2>#3<BR>Cairngorm.99给我们开发Flex程序提供了很不错的架构模式,M/V/C/Remote之间可以做到完全解构。但在实际开发时没有必要死扣,代码结构清晰有活力就好。</FONT></P><img src ="http://www.blogjava.net/sakis/aggbug/12342.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/sakis/" target="_blank">Duran's technical life</a> 2005-09-07 21:49 <a href="http://www.blogjava.net/sakis/archive/2005/09/07/12342.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Hibernate一对一关联实用介绍</title><link>http://www.blogjava.net/sakis/archive/2005/09/06/12200.html</link><dc:creator>Duran's technical life</dc:creator><author>Duran's technical life</author><pubDate>Tue, 06 Sep 2005 05:16:00 GMT</pubDate><guid>http://www.blogjava.net/sakis/archive/2005/09/06/12200.html</guid><wfw:comment>http://www.blogjava.net/sakis/comments/12200.html</wfw:comment><comments>http://www.blogjava.net/sakis/archive/2005/09/06/12200.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/sakis/comments/commentRss/12200.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/sakis/services/trackbacks/12200.html</trackback:ping><description><![CDATA[<P><FONT face="Courier New" size=2>Hibernate一对一关联实用介绍</FONT></P>
<P><FONT face="Courier New" size=2>#0 <BR>书和文档上写的都不是特清楚的。自己记下来。</FONT></P>
<P><FONT face="Courier New" size=2>#1 Using a PK association</FONT></P>
<P><FONT face="Courier New" size=2>#1.1 POJO with XDolclet annotation<BR>public class Customer {<BR>&nbsp;/**<BR>&nbsp; * @return Returns the shoppingCart.<BR>&nbsp; * @hibernate.many-to-one cascade="delete" column="shopping_cart_id" <BR>&nbsp; *&nbsp; unique="true" foreign-key="FK_SHOPPING_CART__CUSTOMER" <BR>&nbsp; */<BR>&nbsp;public ShoppingCart getShoppingCart() {<BR>&nbsp;&nbsp;return shoppingCart;<BR>&nbsp;}<BR>}</FONT></P>
<P><FONT face="Courier New" size=2>public class ShoppingCart {<BR>&nbsp;/**<BR>&nbsp; * @return Returns the customer.<BR>&nbsp; * @hibernate.one-to-one property-ref="shoppingCart"<BR>&nbsp; */<BR>&nbsp;public Customer getCustomer() {<BR>&nbsp;&nbsp;return customer;<BR>&nbsp;}<BR>}</FONT></P>
<P><FONT face="Courier New" size=2>property-ref="shoppingCart" 告诉Hibernate ShoppingCart#customer和Customer#shoppingCart是反向的关系。所以Hibernate知道如何从ShoppingCart#getCustomer中检索到相应的customer对象。取出某个Customer对象时，Hibernate会生成DEBUG SQL:324 - 3中的SQL语句。</FONT></P>
<P><FONT face="Courier New" size=2>#1.2 HBM<BR>Customer.hbm.xml<BR>&lt;many-to-one<BR>&nbsp;&nbsp;&nbsp; name="shoppingCart"<BR>&nbsp;&nbsp;&nbsp; class="ShoppingCart"<BR>&nbsp;&nbsp;&nbsp; cascade="delete"<BR>&nbsp;&nbsp;&nbsp; outer-join="auto"<BR>&nbsp;&nbsp;&nbsp; foreign-key="FK_SHOPPING_CART__CUSTOMER"<BR>&nbsp;&nbsp;&nbsp; column="shopping_cart_id"<BR>/&gt;</FONT></P>
<P><FONT face="Courier New" size=2>ShoppingCart.hbm.xml<BR>&lt;one-to-one<BR>&nbsp;&nbsp;&nbsp; name="customer"<BR>&nbsp;&nbsp;&nbsp; class="Customer"<BR>&nbsp;&nbsp;&nbsp; cascade="none"<BR>&nbsp;&nbsp;&nbsp; outer-join="auto"<BR>&nbsp;&nbsp;&nbsp; constrained="false"<BR>&nbsp;&nbsp;&nbsp; property-ref="shoppingCart"<BR>/&gt;</FONT></P>
<P><FONT face="Courier New" size=2>#1.3 SCHEMA SQL<BR>create table CUSTOMER (<BR>&nbsp;&nbsp;&nbsp; ID bigint generated by default as identity (start with 1),<BR>&nbsp;&nbsp;&nbsp; SHOPPING_CART_ID bigint,<BR>&nbsp;&nbsp;&nbsp; primary key (ID)<BR>)</FONT></P>
<P><FONT face="Courier New" size=2>create table SHOPPING_CART (<BR>&nbsp;&nbsp;&nbsp; ID bigint generated by default as identity (start with 1)<BR>&nbsp;&nbsp;&nbsp; primary key (ID)<BR>)</FONT></P>
<P><FONT face="Courier New" size=2>alter table CUSTOMER <BR>&nbsp;&nbsp;&nbsp; add constraint FK_SHOPPING_CART__CUSTOMER <BR>&nbsp;&nbsp;&nbsp; foreign key (SHOPPING_CART_ID) <BR>&nbsp;&nbsp;&nbsp; references SHOPPING_CART</FONT></P>
<P><FONT face="Courier New" size=2>#1.4 Query SQL<BR>DEBUG SQL:324 - 1<BR>select customer0_.ID as ID, customer0_.SHOPPING_CART_ID as SHOPPING2_3_, customer0_.USERNAME as USERNAME3_, customer0_.PWD as PWD3_ <BR>from CUSTOMER customer0_ <BR>where customer0_.USERNAME=? and customer0_.PWD=?</FONT></P>
<P><FONT face="Courier New" size=2>DEBUG SQL:324 - 2<BR>select shoppingca0_.ID as ID0_, shoppingca0_.TOTAL as TOTAL8_0_ <BR>from SHOPPING_CART shoppingca0_ <BR>where shoppingca0_.ID=?</FONT></P>
<P><FONT face="Courier New" size=2>DEBUG SQL:324 - 3<BR>select customer0_.ID as ID1_, customer0_.SHOPPING_CART_ID as SHOPPING2_3_1_, customer0_.USERNAME as USERNAME3_1_, customer0_.PWD as PWD3_1_, shoppingca1_.ID as ID0_, shoppingca1_.TOTAL as TOTAL8_0_ <BR>from <BR>&nbsp;CUSTOMER customer0_ <BR>&nbsp;left outer join <BR>&nbsp;SHOPPING_CART shoppingca1_ <BR>&nbsp;on customer0_.SHOPPING_CART_ID=shoppingca1_.ID <BR>where customer0_.SHOPPING_CART_ID=?</FONT></P>
<P><BR><FONT face="Courier New" size=2>#2 Using a FK association</FONT></P>
<P><FONT face="Courier New" size=2>#2.1 POJO with XDolclet annotation<BR>public class Customer {<BR>&nbsp;/**<BR>&nbsp; * @return Returns the shoppingCart.<BR>&nbsp; * @hibernate.one-to-one cascade="delete" <BR>&nbsp; */<BR>&nbsp;public ShoppingCart getShoppingCart() {<BR>&nbsp;&nbsp;return shoppingCart;<BR>&nbsp;}<BR>}</FONT></P>
<P><FONT face="Courier New" size=2>public class ShoppingCart {<BR>&nbsp;/**<BR>&nbsp; * @return Returns the id.<BR>&nbsp; * @hibernate.id generator-class="foreign"<BR>&nbsp; * @hibernate.generator-param name="property" value="customer"<BR>&nbsp; */<BR>&nbsp;public Long getId() {<BR>&nbsp;&nbsp;return id();<BR>&nbsp;}</FONT></P>
<P><FONT face="Courier New" size=2>&nbsp;/**<BR>&nbsp; * @return Returns the customer.<BR>&nbsp; * @hibernate.one-to-one constrained="true" foreign-key="FK_CUSTOMER__SHOPPING_CART"<BR>&nbsp; */<BR>&nbsp;public Customer getCustomer() {<BR>&nbsp;&nbsp;return customer;<BR>&nbsp;}<BR>}</FONT></P>
<P><FONT face="Courier New" size=2>constrained="true" 告诉Hibernate ShoppingCart的PK还应该是一个FK，这个FK引用Customer的PK。还需要多做一点工作，声明ShoppingCart的PK生成策略是foreign，对应ShoppingCart#customer。这和上面一句话不是一个意思嘛，FT~~</FONT></P>
<P><FONT face="Courier New" size=2>#2.2 HBM<BR>Customer.hbm.xml<BR>&lt;one-to-one<BR>&nbsp;&nbsp;&nbsp; name="shoppingCart"<BR>&nbsp;&nbsp;&nbsp; class="ShoppingCart"<BR>&nbsp;&nbsp;&nbsp; cascade="delete"<BR>&nbsp;&nbsp;&nbsp; outer-join="auto"<BR>&nbsp;&nbsp;&nbsp; constrained="false"<BR>/&gt;</FONT></P>
<P><FONT face="Courier New" size=2>ShoppingCart.hbm.xml<BR>&lt;id<BR>&nbsp;&nbsp;&nbsp; name="id"<BR>&nbsp;&nbsp;&nbsp; column="id"<BR>&nbsp;&nbsp;&nbsp; type="java.lang.Long"<BR>&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;generator class="foreign"&gt;<BR>&nbsp;&lt;param name="property"&gt;customer&lt;/param&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;/generator&gt;<BR>&lt;/id&gt;</FONT></P>
<P><FONT face="Courier New" size=2>&lt;one-to-one<BR>&nbsp;&nbsp;&nbsp; name="customer"<BR>&nbsp;&nbsp;&nbsp; class="Customer"<BR>&nbsp;&nbsp;&nbsp; cascade="none"<BR>&nbsp;&nbsp;&nbsp; outer-join="auto"<BR>&nbsp;&nbsp;&nbsp; constrained="true"<BR>/&gt;</FONT></P>
<P><FONT face="Courier New" size=2>#2.3 SCHEMA SQL<BR>create table CUSTOMER (<BR>&nbsp;&nbsp;&nbsp; ID bigint generated by default as identity (start with 1),<BR>&nbsp;&nbsp;&nbsp; primary key (ID)<BR>)</FONT></P>
<P><FONT face="Courier New" size=2>create table SHOPPING_CART (<BR>&nbsp;&nbsp;&nbsp; ID bigint not null,<BR>&nbsp;&nbsp;&nbsp; TOTAL integer,<BR>&nbsp;&nbsp;&nbsp; primary key (ID)<BR>)</FONT></P>
<P><FONT face="Courier New" size=2>alter table SHOPPING_CART <BR>&nbsp;&nbsp;&nbsp; add constraint FK_CUSTOMER__SHOPPING_CART <BR>&nbsp;&nbsp;&nbsp; foreign key (ID) <BR>&nbsp;&nbsp;&nbsp; references CUSTOMER</FONT></P>
<P><FONT face="Courier New" size=2>#2.4 Query SQL<BR>DEBUG SQL:324 - <BR>select customer0_.ID as ID, customer0_.USERNAME as USERNAME3_, customer0_.PWD as PWD3_ <BR>from CUSTOMER customer0_ <BR>where customer0_.USERNAME=? and customer0_.PWD=?</FONT></P>
<P><FONT face="Courier New" size=2>DEBUG SQL:324 - <BR>select shoppingca0_.ID as ID0_, shoppingca0_.TOTAL as TOTAL8_0_ <BR>from SHOPPING_CART shoppingca0_ <BR>where shoppingca0_.ID=?</FONT></P>
<P><FONT face="Courier New" size=2>这个“真正”的one-to-one的好处是少条关联SQL语句，看到了吗？</FONT></P><img src ="http://www.blogjava.net/sakis/aggbug/12200.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/sakis/" target="_blank">Duran's technical life</a> 2005-09-06 13:16 <a href="http://www.blogjava.net/sakis/archive/2005/09/06/12200.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Avoid tomcat "out of memory" error</title><link>http://www.blogjava.net/sakis/archive/2005/08/12/9982.html</link><dc:creator>Duran's technical life</dc:creator><author>Duran's technical life</author><pubDate>Fri, 12 Aug 2005 09:38:00 GMT</pubDate><guid>http://www.blogjava.net/sakis/archive/2005/08/12/9982.html</guid><wfw:comment>http://www.blogjava.net/sakis/comments/9982.html</wfw:comment><comments>http://www.blogjava.net/sakis/archive/2005/08/12/9982.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/sakis/comments/commentRss/9982.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/sakis/services/trackbacks/9982.html</trackback:ping><description><![CDATA[1 &nbsp;Open the Apache Tomcat configuration app in sys tray, and on the "Java" tab, bump up the initial memory pool size and the maximum memory pool size to 512 Initial and 768 Max, click Ok. <BR>2&nbsp; In \Program Files\Apache software Foundation\Tomcat 5.0\bin\catalina.bat, in the last section immediately after "rem Execute Java with the applicable properties", insert this line, set CATALINA_OPTS=-mx1024m. Save the file. <img src ="http://www.blogjava.net/sakis/aggbug/9982.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/sakis/" target="_blank">Duran's technical life</a> 2005-08-12 17:38 <a href="http://www.blogjava.net/sakis/archive/2005/08/12/9982.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HelloWorld</title><link>http://www.blogjava.net/sakis/archive/2005/08/09/9631.html</link><dc:creator>Duran's technical life</dc:creator><author>Duran's technical life</author><pubDate>Tue, 09 Aug 2005 01:38:00 GMT</pubDate><guid>http://www.blogjava.net/sakis/archive/2005/08/09/9631.html</guid><wfw:comment>http://www.blogjava.net/sakis/comments/9631.html</wfw:comment><comments>http://www.blogjava.net/sakis/archive/2005/08/09/9631.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/sakis/comments/commentRss/9631.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/sakis/services/trackbacks/9631.html</trackback:ping><description><![CDATA[<P>在google里敲了“HelloWolrd”，再点“手气不错”，出来了这样一个页面：<A href="http://www2.latech.edu/~acm/HelloWorld.shtml">http://www2.latech.edu/~acm/HelloWorld.shtml</A><BR><BR><STRONG><FONT size=5>Hello World!</FONT></STRONG></P>
<P>Welcome to the ACM <B>"Hello World"</B> project. Everyone has seen the Hello World program used as a first exposure to a new language or environment. We are attempting to collect examples for as many languages and related programming environments (shells etc.) as possible. </P>
<HR>

<P>Aproximate number of examples:<B>204&nbsp;&nbsp;&nbsp;&nbsp; &lt;----wow~~~</B><BR>This page has been accessed <A href="http://www.webtools.org/counter/">33274</A> times.<BR><EM>Last updated: January 20, 2005&nbsp;&nbsp;&nbsp;<BR><BR><BR></EM>看看C的，经典HelloWorld<BR><FONT face="Courier New" size=2>#include &lt;stdio.h&gt;<BR>main()<BR>{<BR>&nbsp; for(;;)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf ("Hello World!\n");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>}</FONT><BR><BR>这也是HelloWolrd？！<BR>a 1986 entry from Bruce Holloway: <BR><BR><FONT face="Courier New" size=2>#include "stdio.h"<BR>#define e 3<BR>#define g (e/e)<BR>#define h ((g+e)/2)<BR>#define f (e-g-h)<BR>#define j (e*e-g)<BR>#define k (j-h)<BR>#define l(x) tab2[x]/h<BR>#define m(n,a) ((n&amp;(a))==(a))<BR><BR>long tab1[]={ 989L,5L,26L,0L,88319L,123L,0L,9367L };<BR>int tab2[]={ 4,6,10,14,22,26,34,38,46,58,62,74,82,86 };<BR><BR>main(m1,s) char *s; {<BR>&nbsp;&nbsp;&nbsp; int a,b,c,d,o[k],n=(int)s;<BR>&nbsp;&nbsp;&nbsp; if(m1==1){ char b[2*j+f-g]; main(l(h+e)+h+e,b); printf(b); }<BR>&nbsp;&nbsp;&nbsp; else switch(m1-=h){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case f:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a=(b=(c=(d=g)&lt;&lt;g)&lt;'&lt;g)&lt;&lt;g;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return(m(n,a|c)|m(n,b)|m(n,a|d)|m(n,c|d));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case h:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(a=f;a<J;++A)IF(TAB1[A]&&!(TAB1[A]%((LONG)L(N))))RETURN(A); case g: if(n<h)return(g); if(n<j){n-="g;c='D';o[f]=h;o[g]=f;}" else{c="\r" -?\b?;n-="j-g;o[f]=o[g]=g;}" if((b="n)">=e)for(b=g&lt;&lt;g;b&lt;n;++b)o[b]=o[b-h]+o[b-g]+c;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return(o[b-g]%n+k-h);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; default:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(m1-=e) main(m1-g+e+h,s+g); else *(s+g)=f;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(*s=a=f;a&lt;e;) *s=(*s&lt;&lt;e)|main(h+a++,(char *)m1);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>}<BR></FONT><BR>曾经最短的HelloWorld（<A href="mailto:Jari.Arkko@lmf.eua.ericsson.se">Jari.Arkko@lmf.eua.ericsson.se</A>）<BR><FONT size=2><STRONG>jar.1.c</STRONG> <BR></FONT><FONT face="Courier New" size=2>char*_="Hello world.\n";<BR><BR>ln -s /dev/tty jar.1.o<BR>cc -c jar.1.c</FONT><BR><BR><BR>现在最短的HelloWorld&nbsp;（Jyrki Holopainen）<BR><STRONG><FONT size=2>";main(){puts("Hello World!");}char*C=".c</FONT></STRONG>&nbsp;&nbsp;<BR><FONT face="Courier New" size=2>char*_=__FILE__;</FONT></P><img src ="http://www.blogjava.net/sakis/aggbug/9631.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/sakis/" target="_blank">Duran's technical life</a> 2005-08-09 09:38 <a href="http://www.blogjava.net/sakis/archive/2005/08/09/9631.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Hibernate MySQL 中文乱码问题</title><link>http://www.blogjava.net/sakis/archive/2005/06/10/5894.html</link><dc:creator>Duran's technical life</dc:creator><author>Duran's technical life</author><pubDate>Fri, 10 Jun 2005 13:35:00 GMT</pubDate><guid>http://www.blogjava.net/sakis/archive/2005/06/10/5894.html</guid><wfw:comment>http://www.blogjava.net/sakis/comments/5894.html</wfw:comment><comments>http://www.blogjava.net/sakis/archive/2005/06/10/5894.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.blogjava.net/sakis/comments/commentRss/5894.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/sakis/services/trackbacks/5894.html</trackback:ping><description><![CDATA[<P><FONT face="Courier New"><STRONG>环境</STRONG>：Hibernate 2.1.7 + MySQL4.1（MySQL的编码已设置为utf8）<BR><STRONG>问题</STRONG>：通过Hibernate向MySQL写入中文后，通过Hibernate取回数据，在console中打印java对象显示正常。但在MySQL Query Browser中看到的是乱码，传给前端的Flex也是乱码。<BR><STRONG>原因</STRONG>：Hibernate的基础还是JDBC，所以一样需要设置characterEncoding！<BR><STRONG>解决方法</STRONG>：<BR>在hibernate.cfg.xml中应该这样写</FONT></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><FONT face="Courier New"><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">property&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="connection.url"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">jdbc:mysql://localhost:3306/test?useUnicode=true</SPAN><SPAN style="COLOR: #ff0000">&amp;amp;</SPAN><SPAN style="COLOR: #000000">characterEncoding=UTF-8</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">property</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></FONT></DIV></DIV><FONT face="Courier New">如果用hibernate.properties<BR>#hibernate.connection.url jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=UTF-8<BR><BR>ps：处理中文的话，characterEncoding用GBK一样可以。<BR>但字节编码问题最好的解决方法还是统一使用UTF-8！！！</FONT><img src ="http://www.blogjava.net/sakis/aggbug/5894.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/sakis/" target="_blank">Duran's technical life</a> 2005-06-10 21:35 <a href="http://www.blogjava.net/sakis/archive/2005/06/10/5894.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[OS]Reader-Writer Problem的三种实现</title><link>http://www.blogjava.net/sakis/archive/2005/05/19/4844.html</link><dc:creator>Duran's technical life</dc:creator><author>Duran's technical life</author><pubDate>Thu, 19 May 2005 01:54:00 GMT</pubDate><guid>http://www.blogjava.net/sakis/archive/2005/05/19/4844.html</guid><wfw:comment>http://www.blogjava.net/sakis/comments/4844.html</wfw:comment><comments>http://www.blogjava.net/sakis/archive/2005/05/19/4844.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/sakis/comments/commentRss/4844.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/sakis/services/trackbacks/4844.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 参考package EDU.oswego.cs.dl.util.concurrent1public&nbsp;interface&nbsp;Sync&nbsp;{2&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;void&nbsp;acquire();3&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;void&nbsp;release();4...&nbsp;&nbsp;<a href='http://www.blogjava.net/sakis/archive/2005/05/19/4844.html'>阅读全文</a><img src ="http://www.blogjava.net/sakis/aggbug/4844.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/sakis/" target="_blank">Duran's technical life</a> 2005-05-19 09:54 <a href="http://www.blogjava.net/sakis/archive/2005/05/19/4844.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[笔记]Hibernate - Parent/Child relationship &amp; inverse usage</title><link>http://www.blogjava.net/sakis/archive/2005/05/19/4838.html</link><dc:creator>Duran's technical life</dc:creator><author>Duran's technical life</author><pubDate>Thu, 19 May 2005 01:28:00 GMT</pubDate><guid>http://www.blogjava.net/sakis/archive/2005/05/19/4838.html</guid><wfw:comment>http://www.blogjava.net/sakis/comments/4838.html</wfw:comment><comments>http://www.blogjava.net/sakis/archive/2005/05/19/4838.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/sakis/comments/commentRss/4838.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/sakis/services/trackbacks/4838.html</trackback:ping><description><![CDATA[<FONT face="Courier New" size=2>Suppose we start with a simple &lt;one-to-many&gt; association from Parent to Child. </FONT>
<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><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008080">&nbsp;1</SPAN><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">hibernate-mapping&nbsp;</SPAN><SPAN style="COLOR: #ff0000">package</SPAN><SPAN style="COLOR: #0000ff">="org.hibernate.auction.model"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008080">&nbsp;2</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&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">="Parent"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;table</SPAN><SPAN style="COLOR: #0000ff">="PARENT"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008080">&nbsp;3</SPAN><SPAN style="COLOR: #000000"><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">id&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="id"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;column</SPAN><SPAN style="COLOR: #0000ff">="PARENT_ID"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;type</SPAN><SPAN style="COLOR: #0000ff">="long"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008080">&nbsp;4</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">generator&nbsp;</SPAN><SPAN style="COLOR: #ff0000">class</SPAN><SPAN style="COLOR: #0000ff">="native"</SPAN><SPAN style="COLOR: #0000ff">&gt;&lt;/</SPAN><SPAN style="COLOR: #800000">generator</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008080">&nbsp;5</SPAN><SPAN style="COLOR: #000000"><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">id</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008080">&nbsp;6</SPAN><SPAN style="COLOR: #000000"><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">set&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="children"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008080">&nbsp;7</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">key&nbsp;</SPAN><SPAN style="COLOR: #ff0000">column</SPAN><SPAN style="COLOR: #0000ff">="MY_PARENT_ID"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008080">&nbsp;8</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">one-to-many&nbsp;</SPAN><SPAN style="COLOR: #ff0000">class</SPAN><SPAN style="COLOR: #0000ff">="org.hibernate.auction.model.Child"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008080">&nbsp;9</SPAN><SPAN style="COLOR: #000000"><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">set</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008080">10</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">class</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008080">11</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&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">="Child"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;table</SPAN><SPAN style="COLOR: #0000ff">="CHILD"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008080">12</SPAN><SPAN style="COLOR: #000000"><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">id&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="id"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;column</SPAN><SPAN style="COLOR: #0000ff">="CHILD_ID"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;type</SPAN><SPAN style="COLOR: #0000ff">="long"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008080">13</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">generator&nbsp;</SPAN><SPAN style="COLOR: #ff0000">class</SPAN><SPAN style="COLOR: #0000ff">="native"</SPAN><SPAN style="COLOR: #0000ff">&gt;&lt;/</SPAN><SPAN style="COLOR: #800000">generator</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008080">14</SPAN><SPAN style="COLOR: #000000"><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">id</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008080">15</SPAN><SPAN style="COLOR: #000000"><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">property&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="name"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;column</SPAN><SPAN style="COLOR: #0000ff">="NAME"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;type</SPAN><SPAN style="COLOR: #0000ff">="string"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008080">16</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">class</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008080">17</SPAN><SPAN style="COLOR: #000000"><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></FONT></FONT></DIV></DIV>
<P><FONT face="Courier New" size=2>If we were to execute the following code<BR></FONT></P>
<P><FONT face="Courier New" size=2></FONT></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><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008080">&nbsp;1</SPAN><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">Parent&nbsp;p&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Parent(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000">&nbsp;HashSet());&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;2</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>Child&nbsp;c1&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Child(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;String(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">c1</SPAN><SPAN style="COLOR: #000000">"</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000">));<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;3</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR></SPAN><SPAN style="COLOR: #008080">&nbsp;4</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_84_519_Open_Image onclick="this.style.display='none'; Codehighlighter1_84_519_Open_Text.style.display='none'; Codehighlighter1_84_519_Closed_Image.style.display='inline'; Codehighlighter1_84_519_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_84_519_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_84_519_Closed_Text.style.display='none'; Codehighlighter1_84_519_Open_Image.style.display='inline'; Codehighlighter1_84_519_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">try</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN id=Codehighlighter1_84_519_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></FONT></FONT><SPAN id=Codehighlighter1_84_519_Open_Text><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;5</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;session&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000">&nbsp;sessionFactory.openSession();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;6</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;tx&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000">&nbsp;session.beginTransaction();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;7</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;session.save(p);<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;8</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;Long&nbsp;pid&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000">&nbsp;p.getId();<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;9</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;tx.commit();<BR></SPAN><SPAN style="COLOR: #008080">10</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;session.close();<BR></SPAN><SPAN style="COLOR: #008080">11</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">12</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;session&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000">&nbsp;sessionFactory.openSession();<BR></SPAN><SPAN style="COLOR: #008080">13</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;tx&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000">&nbsp;session.beginTransaction();<BR></SPAN><SPAN style="COLOR: #008080">14</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;Parent&nbsp;pp&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;(Parent)&nbsp;session.load(Parent.</SPAN><SPAN style="COLOR: #0000ff">class</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000">,&nbsp;pid);&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">15</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;pp.getChildren().add(c1);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">16</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;session.save(c1);<BR></SPAN><SPAN style="COLOR: #008080">17</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;session.flush();<BR></SPAN><SPAN style="COLOR: #008080">18</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;tx.commit();<BR></SPAN><SPAN style="COLOR: #008080">19</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR></SPAN><SPAN style="COLOR: #008080">20</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_550_552_Open_Image onclick="this.style.display='none'; Codehighlighter1_550_552_Open_Text.style.display='none'; Codehighlighter1_550_552_Closed_Image.style.display='inline'; Codehighlighter1_550_552_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_550_552_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_550_552_Closed_Text.style.display='none'; Codehighlighter1_550_552_Open_Image.style.display='inline'; Codehighlighter1_550_552_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top>}</SPAN></FONT></FONT></SPAN><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000">&nbsp;(HibernateException&nbsp;e)&nbsp;</SPAN><SPAN id=Codehighlighter1_550_552_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></FONT></FONT><SPAN id=Codehighlighter1_550_552_Open_Text><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">21</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></FONT></FONT></SPAN></DIV></DIV>
<P><FONT face="Courier New" size=2>Hibernate would issue two SQL statements:<BR>- an INSERT to create the record for c<BR>- an UPDATE to create the link from p to c</FONT></P>
<P><FONT face="Courier New" size=2>Hibernate: insert into PARENT values ( )<BR>Hibernate: select parent0_.PARENT_ID as PARENT_ID0_ from PARENT parent0_ where parent0_.PARENT_ID=?<BR>Hibernate: select children0_.MY_PARENT_ID as MY_PAREN3___, children0_.CHILD_ID as CHILD_ID__, children0_.CHILD_ID as CHILD_ID0_, children0_.NAME as NAME0_ from CHILD children0_ where children0_.MY_PARENT_ID=?</FONT></P>
<P><FONT face="Courier New" size=2>- Hibernate: insert into CHILD (NAME) values (?)<BR>- Hibernate: update CHILD set MY_PARENT_ID=? where CHILD_ID=?</FONT></P>
<P><FONT face="Courier New" size=2>This is not only inefficient, but also violates any NOT NULL constraint on the <BR>MY_PARENT_ID column.</FONT></P>
<P><FONT face="Courier New" size=2>**********1<BR>The underlying cause is that the link (the foreign key parent_id) from p to c is not considered part of the state of the Child object and is therefore not created in the INSERT. So the solution is to make the link part of the Child mapping.<BR>**********1</FONT></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><FONT face="Courier New"><FONT size=2><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&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">="my_parent"</SPAN></FONT></FONT><SPAN style="COLOR: #ff0000"><BR><FONT face="Courier New" size=2><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;class</FONT></SPAN><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #0000ff">="org.hibernate.auction.model.Parent"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;column</SPAN><SPAN style="COLOR: #0000ff">="MY_PARENT_ID"</SPAN></FONT></FONT><SPAN style="COLOR: #ff0000"><BR><FONT face="Courier New" size=2><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;not-null</FONT></SPAN><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #0000ff">="true"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR><FONT face="Courier New" size=2><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;</FONT></SPAN><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">many-to-one</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></FONT></FONT></DIV></DIV>
<P><FONT face="Courier New" size=2>**********2<BR>Now that the Child entity is managing the state of the link, we tell the collection not to update the link. We use the inverse attribute.<BR>**********2</FONT></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><FONT face="Courier New"><FONT size=2><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&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">="children"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;inverse</SPAN><SPAN style="COLOR: #0000ff">="true"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR><FONT face="Courier New" size=2><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</FONT></SPAN><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">key&nbsp;</SPAN><SPAN style="COLOR: #ff0000">column</SPAN><SPAN style="COLOR: #0000ff">="MY_PARENT_ID"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR><FONT face="Courier New" size=2><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</FONT></SPAN><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">one-to-many&nbsp;</SPAN><SPAN style="COLOR: #ff0000">class</SPAN><SPAN style="COLOR: #0000ff">="org.hibernate.auction.model.Child"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR><FONT face="Courier New" size=2><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;</FONT></SPAN><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">set</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></FONT></FONT></DIV></DIV>
<P><FONT face="Courier New" size=2>The following code would be used to add a new Child<BR></FONT></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><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008080">1</SPAN><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">Parent&nbsp;pp&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;(Parent)&nbsp;session.load(Parent.</SPAN><SPAN style="COLOR: #0000ff">class</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000">,&nbsp;pid);&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">2</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>pp.getChildren().add(c1);<BR></SPAN><SPAN style="COLOR: #008080">3</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>c1.setMy_parent(pp);&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">the&nbsp;link&nbsp;is&nbsp;part&nbsp;of&nbsp;the&nbsp;Child&nbsp;object's&nbsp;state.&nbsp;@see***1&nbsp;</SPAN></FONT></FONT><SPAN style="COLOR: #008000"><BR></SPAN><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008080">4</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">session.save(c1);</SPAN></FONT></FONT></DIV></DIV>
<P><FONT face="Courier New" size=2>And now, only one SQL INSERT would be issued!<BR>To tighten things up a bit, we could create an addChild() method of Parent.</FONT></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><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008080">1</SPAN><IMG id=Codehighlighter1_30_72_Open_Image onclick="this.style.display='none'; Codehighlighter1_30_72_Open_Text.style.display='none'; Codehighlighter1_30_72_Closed_Image.style.display='inline'; Codehighlighter1_30_72_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_30_72_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_30_72_Closed_Text.style.display='none'; Codehighlighter1_30_72_Open_Image.style.display='inline'; Codehighlighter1_30_72_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;addChild(Child&nbsp;c)&nbsp;</SPAN><SPAN id=Codehighlighter1_30_72_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></FONT></FONT><SPAN id=Codehighlighter1_30_72_Open_Text><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">2</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;c.setParent(</SPAN><SPAN style="COLOR: #0000ff">this</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">3</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;children.add(c);<BR></SPAN><SPAN style="COLOR: #008080">4</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></FONT></FONT></SPAN></DIV></DIV>
<P><FONT face="Courier New" size=2>Now, the code to add a Child looks like</FONT></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><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008080">1</SPAN><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">Parent&nbsp;p&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;(Parent)&nbsp;session.load(Parent.</SPAN><SPAN style="COLOR: #0000ff">class</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000">,&nbsp;pid);<BR></SPAN><SPAN style="COLOR: #008080">2</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>Child&nbsp;c&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000">&nbsp;Child();<BR></SPAN><SPAN style="COLOR: #008080">3</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>p.addChild(c);&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;1.let&nbsp;both&nbsp;side&nbsp;of&nbsp;the&nbsp;association&nbsp;knows&nbsp;each&nbsp;other.</SPAN></FONT></FONT><SPAN style="COLOR: #008000"><BR></SPAN><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008080">4</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">session.save(c);&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;2.save&nbsp;the&nbsp;non-verse&nbsp;side</SPAN></FONT></FONT></DIV></DIV>
<P><FONT face="Courier New" size=2>=========================================================================================<BR>CONCLUSION:<BR>1.The non-inverse(inverse="false") side is responsible to save the in-memory representation (object) to the database .<BR>--- you should save the child: session.save(c);<BR>2.Changes made only to the inverse end of the association are not persisted.<BR>--- you needn't update the parent: //session.update(p);<BR></FONT></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><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008080">&nbsp;1</SPAN><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">session&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000">&nbsp;sessionFactory.openSession();<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;2</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>tx&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000">&nbsp;session.beginTransaction();<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;3</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>Parent&nbsp;pp&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;(Parent)&nbsp;session.load(Parent.</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Long(</SPAN><SPAN style="COLOR: #000000">1</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000">));&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;4</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>pp.getChildren().add(c1);&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">the&nbsp;parent(pp)&nbsp;now&nbsp;knowns&nbsp;about&nbsp;the&nbsp;relationship</SPAN></FONT></FONT><SPAN style="COLOR: #008000"><BR></SPAN><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008080">&nbsp;5</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">c1.setMy_parent(pp);&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008000">the&nbsp;child(c1)&nbsp;now&nbsp;knows&nbsp;about&nbsp;the&nbsp;relationship<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;6</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR></SPAN><SPAN style="COLOR: #008080">&nbsp;7</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #008000">//</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008000">&nbsp;when&nbsp;cascade="save-update",&nbsp;update(p)&nbsp;will&nbsp;cause&nbsp;all&nbsp;p's<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;8</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #008000">//</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008000">&nbsp;referencing&nbsp;children&nbsp;become&nbsp;persistence(cascade&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;9</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #008000">//</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008000">&nbsp;saveOrUpdate()&nbsp;operation&nbsp;to&nbsp;parent's&nbsp;all&nbsp;children).<BR></SPAN><SPAN style="COLOR: #008080">10</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #008000">//</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008000">&nbsp;So,&nbsp;it's&nbsp;same&nbsp;as&nbsp;you&nbsp;explicitly&nbsp;call&nbsp;session.save(c1).<BR></SPAN><SPAN style="COLOR: #008080">11</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR></SPAN><SPAN style="COLOR: #008080">12</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #008000">//</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008000">&nbsp;when&nbsp;cascade="none"(default),&nbsp;update(p)&nbsp;will&nbsp;just&nbsp;cause<BR></SPAN><SPAN style="COLOR: #008080">13</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #008000">//</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008000">&nbsp;p&nbsp;become&nbsp;persistence.<BR></SPAN><SPAN style="COLOR: #008080">14</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #008000">//</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008000">&nbsp;And&nbsp;inverse="true",&nbsp;update(p)&nbsp;just&nbsp;persists&nbsp;p,&nbsp;but&nbsp;not&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">15</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;persists&nbsp;the&nbsp;link&nbsp;between&nbsp;p&nbsp;and&nbsp;c1.&nbsp;@see&nbsp;***2</SPAN></FONT></FONT><SPAN style="COLOR: #008000"><BR></SPAN><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008080">16</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000">session.update(pp);&nbsp;&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">17</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">session.save(c1);&nbsp;&nbsp;</SPAN></FONT></FONT><SPAN style="COLOR: #008000"><BR></SPAN><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008080">18</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000">session.flush();<BR></SPAN><SPAN style="COLOR: #008080">19</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>tx.commit();<BR></SPAN><SPAN style="COLOR: #008080">20</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></FONT></FONT></DIV></DIV>
<P><BR><FONT face="Courier New" size=2>Hibernate: select parent0_.PARENT_ID as PARENT_ID0_ from PARENT parent0_ where parent0_.PARENT_ID=?<BR>Hibernate: select children0_.MY_PARENT_ID as MY_PAREN3___, children0_.CHILD_ID as CHILD_ID__, children0_.CHILD_ID as CHILD_ID0_, children0_.NAME as NAME0_, children0_.MY_PARENT_ID as MY_PAREN3_0_ from CHILD children0_ where children0_.MY_PARENT_ID=?</FONT></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><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008080">&nbsp;1</SPAN><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">session&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000">&nbsp;sessionFactory.openSession();<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;2</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>tx&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000">&nbsp;session.beginTransaction();<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;3</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>Parent&nbsp;pp&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;(Parent)&nbsp;session.load(Parent.</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Long(</SPAN><SPAN style="COLOR: #000000">1</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000">));&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;4</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>pp.getChildren().add(c1);<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;5</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>c1.setMy_parent(pp);<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;6</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #008000">//</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008000">session.update(pp);<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;7</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR></SPAN><SPAN style="COLOR: #008080">&nbsp;8</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #008000">//</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008000">&nbsp;when&nbsp;save(c1),&nbsp;because&nbsp;c1&nbsp;holds&nbsp;a&nbsp;reference&nbsp;to&nbsp;its&nbsp;Parent<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;9</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;(my_parent),&nbsp;so&nbsp;p&nbsp;become&nbsp;persistence&nbsp;too.</SPAN></FONT></FONT><SPAN style="COLOR: #008000"><BR></SPAN><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008080">10</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">session.save(c1);&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">The&nbsp;relationship&nbsp;will&nbsp;be&nbsp;saved.&nbsp;@see&nbsp;***1</SPAN></FONT></FONT><SPAN style="COLOR: #008000"><BR></SPAN><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #008080">11</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000">session.flush();<BR></SPAN><SPAN style="COLOR: #008080">12</SPAN></FONT></FONT><FONT face="Courier New"><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>tx.commit();<BR></SPAN><SPAN style="COLOR: #008080">13</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></FONT></FONT></DIV></DIV>
<P><BR><FONT face="Courier New" size=2>Hibernate: select parent0_.PARENT_ID as PARENT_ID0_ from PARENT parent0_ where parent0_.PARENT_ID=?<BR>Hibernate: select children0_.MY_PARENT_ID as MY_PAREN3___, children0_.CHILD_ID as CHILD_ID__, children0_.CHILD_ID as CHILD_ID0_, children0_.NAME as NAME0_, children0_.MY_PARENT_ID as MY_PAREN3_0_ from CHILD children0_ where children0_.MY_PARENT_ID=?<BR>Hibernate: insert into CHILD (NAME, MY_PARENT_ID) values (?, ?)</FONT></P>
<P><BR><FONT face="Courier New" size=2>&nbsp;</FONT></P><img src ="http://www.blogjava.net/sakis/aggbug/4838.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/sakis/" target="_blank">Duran's technical life</a> 2005-05-19 09:28 <a href="http://www.blogjava.net/sakis/archive/2005/05/19/4838.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>