﻿<?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-andyj2ee-随笔分类-hibernate</title><link>http://www.blogjava.net/andyj2ee/category/1035.html</link><description>java tec sky</description><language>zh-cn</language><lastBuildDate>Wed, 28 Feb 2007 04:06:35 GMT</lastBuildDate><pubDate>Wed, 28 Feb 2007 04:06:35 GMT</pubDate><ttl>60</ttl><item><title>Oracle Blob/Clob 字段写入时产生转型异常Cast Exception</title><link>http://www.blogjava.net/andyj2ee/archive/2006/02/14/30633.html</link><dc:creator>java光环</dc:creator><author>java光环</author><pubDate>Tue, 14 Feb 2006 08:35:00 GMT</pubDate><guid>http://www.blogjava.net/andyj2ee/archive/2006/02/14/30633.html</guid><wfw:comment>http://www.blogjava.net/andyj2ee/comments/30633.html</wfw:comment><comments>http://www.blogjava.net/andyj2ee/archive/2006/02/14/30633.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/andyj2ee/comments/commentRss/30633.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/andyj2ee/services/trackbacks/30633.html</trackback:ping><description><![CDATA[<FONT style="BACKGROUND-COLOR: #ffa500">CLOB clob = (CLOB)us.getStatisticsInfo();<BR></FONT><BR>原因是<BR>java.sql.Blob不能强制传唤成oracle.sql.BLOB<BR><BR>解决方法如下：<BR><BR><FONT style="BACKGROUND-COLOR: #9acd32">SerializableClob lob=(SerializableClob)us.getStatisticsInfo();<BR>CLOB lob2 = (CLOB)lob.getWrappedClob();&nbsp;<BR>Writer out = lob2.getCharacterOutputStream();&nbsp;</FONT>&nbsp;&nbsp; <BR><BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG id=Codehighlighter1_39_1303_Open_Image onclick="this.style.display='none'; Codehighlighter1_39_1303_Open_Text.style.display='none'; Codehighlighter1_39_1303_Closed_Image.style.display='inline'; Codehighlighter1_39_1303_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_39_1303_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_39_1303_Closed_Text.style.display='none'; Codehighlighter1_39_1303_Open_Image.style.display='inline'; Codehighlighter1_39_1303_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;testAdd()&nbsp;</SPAN><SPAN style="COLOR: #0000ff">throws</SPAN><SPAN style="COLOR: #000000">&nbsp;Exception&nbsp;</SPAN><SPAN id=Codehighlighter1_39_1303_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_39_1303_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: #0000ff">byte</SPAN><SPAN style="COLOR: #000000">[]&nbsp;buffer&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">byte</SPAN><SPAN style="COLOR: #000000">[</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">];&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buffer[</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">]&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">1</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;Session&nbsp;s&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_131_1113_Open_Image onclick="this.style.display='none'; Codehighlighter1_131_1113_Open_Text.style.display='none'; Codehighlighter1_131_1113_Closed_Image.style.display='inline'; Codehighlighter1_131_1113_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_131_1113_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_131_1113_Closed_Text.style.display='none'; Codehighlighter1_131_1113_Open_Image.style.display='inline'; Codehighlighter1_131_1113_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_131_1113_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_131_1113_Open_Text><SPAN style="COLOR: #000000">{&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;s&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;sf.openSession();&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;Transaction&nbsp;tx&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;s.beginTransaction();<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;BizUserStatistics&nbsp;us</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;BizUserStatistics();<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;us.setId(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Long(</SPAN><SPAN style="COLOR: #000000">100</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;us.setStatisticsInfo(Hibernate.createClob(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</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;&nbsp;&nbsp;&nbsp;&nbsp;s.save(us);&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;s.flush();&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;s.refresh(us,&nbsp;LockMode.UPGRADE);&nbsp;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CLOB&nbsp;clob&nbsp;=&nbsp;(CLOB)us.getStatisticsInfo();&nbsp;</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;SerializableClob&nbsp;lob</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">(SerializableClob)us.getStatisticsInfo();<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;CLOB&nbsp;lob2&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;(CLOB)lob.getWrappedClob();&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;Writer&nbsp;out&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;lob2.getCharacterOutputStream();<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;String&nbsp;fileName&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">d:/process_log.sql</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;File&nbsp;f&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;File(fileName);&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;FileInputStream&nbsp;fin&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;FileInputStream(f);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&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;StringBuffer&nbsp;sb&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;StringBuffer();<BR><IMG id=Codehighlighter1_918_985_Open_Image onclick="this.style.display='none'; Codehighlighter1_918_985_Open_Text.style.display='none'; Codehighlighter1_918_985_Closed_Image.style.display='inline'; Codehighlighter1_918_985_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_918_985_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_918_985_Closed_Text.style.display='none'; Codehighlighter1_918_985_Open_Image.style.display='inline'; Codehighlighter1_918_985_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">&nbsp;(</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;i&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;&nbsp;i&nbsp;</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">1000</SPAN><SPAN style="COLOR: #000000">;&nbsp;i</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">)</SPAN><SPAN id=Codehighlighter1_918_985_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_918_985_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;&nbsp;&nbsp;&nbsp;&nbsp;sb.append(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&lt;data&gt;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;i&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&lt;/data&gt;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></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;out.write(sb.toString());<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;out.close();<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;s.flush();&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;tx.commit();&nbsp;<BR><IMG id=Codehighlighter1_1135_1178_Open_Image onclick="this.style.display='none'; Codehighlighter1_1135_1178_Open_Text.style.display='none'; Codehighlighter1_1135_1178_Closed_Image.style.display='inline'; Codehighlighter1_1135_1178_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_1135_1178_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1135_1178_Closed_Text.style.display='none'; Codehighlighter1_1135_1178_Open_Image.style.display='inline'; Codehighlighter1_1135_1178_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000">&nbsp;(Exception&nbsp;e)&nbsp;</SPAN><SPAN id=Codehighlighter1_1135_1178_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_1135_1178_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;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();&nbsp;<BR><IMG id=Codehighlighter1_1188_1296_Open_Image onclick="this.style.display='none'; Codehighlighter1_1188_1296_Open_Text.style.display='none'; Codehighlighter1_1188_1296_Closed_Image.style.display='inline'; Codehighlighter1_1188_1296_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_1188_1296_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1188_1296_Closed_Text.style.display='none'; Codehighlighter1_1188_1296_Open_Image.style.display='inline'; Codehighlighter1_1188_1296_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">finally</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN id=Codehighlighter1_1188_1296_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_1188_1296_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;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(s&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_1229_1263_Open_Image onclick="this.style.display='none'; Codehighlighter1_1229_1263_Open_Text.style.display='none'; Codehighlighter1_1229_1263_Closed_Image.style.display='inline'; Codehighlighter1_1229_1263_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_1229_1263_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1229_1263_Closed_Text.style.display='none'; Codehighlighter1_1229_1263_Open_Image.style.display='inline'; Codehighlighter1_1229_1263_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">try</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN id=Codehighlighter1_1229_1263_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_1229_1263_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;&nbsp;&nbsp;&nbsp;&nbsp;s.close();&nbsp;<BR><IMG id=Codehighlighter1_1284_1285_Open_Image onclick="this.style.display='none'; Codehighlighter1_1284_1285_Open_Text.style.display='none'; Codehighlighter1_1284_1285_Closed_Image.style.display='inline'; Codehighlighter1_1284_1285_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_1284_1285_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1284_1285_Closed_Text.style.display='none'; Codehighlighter1_1284_1285_Open_Image.style.display='inline'; Codehighlighter1_1284_1285_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000">&nbsp;(Exception&nbsp;e)</SPAN><SPAN id=Codehighlighter1_1284_1285_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_1284_1285_Open_Text><SPAN style="COLOR: #000000">{}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></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/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN></DIV><BR><img src ="http://www.blogjava.net/andyj2ee/aggbug/30633.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/andyj2ee/" target="_blank">java光环</a> 2006-02-14 16:35 <a href="http://www.blogjava.net/andyj2ee/archive/2006/02/14/30633.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>WARN afterTransactionCompletion() was never called</title><link>http://www.blogjava.net/andyj2ee/archive/2005/10/08/14968.html</link><dc:creator>java光环</dc:creator><author>java光环</author><pubDate>Sat, 08 Oct 2005 01:58:00 GMT</pubDate><guid>http://www.blogjava.net/andyj2ee/archive/2005/10/08/14968.html</guid><wfw:comment>http://www.blogjava.net/andyj2ee/comments/14968.html</wfw:comment><comments>http://www.blogjava.net/andyj2ee/archive/2005/10/08/14968.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/andyj2ee/comments/commentRss/14968.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/andyj2ee/services/trackbacks/14968.html</trackback:ping><description><![CDATA[WARN:<BR>afterTransactionCompletion() was never called<BR>unclosed connection, forgot to call close() on your session?<BR><BR><BR>
<P>警告: afterTransactionCompletion() was never called<BR>
<P>执行了tx = session.beginTransaction();</P>
<P>但是后来没处理tx</P>
<P>应该用tx.commit() or tx.rollback()</P>
<P>一般查询时容易出现此问题</P><img src ="http://www.blogjava.net/andyj2ee/aggbug/14968.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/andyj2ee/" target="_blank">java光环</a> 2005-10-08 09:58 <a href="http://www.blogjava.net/andyj2ee/archive/2005/10/08/14968.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>hibernate ant Hbm2JavaTask Exception of:org.xml.sax.SAXParseException: Attribute "insert" must be declared for element type "discriminator".</title><link>http://www.blogjava.net/andyj2ee/archive/2005/08/19/10504.html</link><dc:creator>java光环</dc:creator><author>java光环</author><pubDate>Fri, 19 Aug 2005 05:52:00 GMT</pubDate><guid>http://www.blogjava.net/andyj2ee/archive/2005/08/19/10504.html</guid><wfw:comment>http://www.blogjava.net/andyj2ee/comments/10504.html</wfw:comment><comments>http://www.blogjava.net/andyj2ee/archive/2005/08/19/10504.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/andyj2ee/comments/commentRss/10504.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/andyj2ee/services/trackbacks/10504.html</trackback:ping><description><![CDATA[<P>&lt;discriminator type="java.lang.String" column="REGION_TYPE"<BR>&nbsp;&nbsp; length="10" force="false" insert="true"/&gt;<BR><BR>Region.hbm.xml(15)<BR>org.xml.sax.SAXParseException: Attribute "insert" must be declared for element type "discriminator".</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.xerces.impl.dtd.XMLDTDValidator.addDTDDefaultAttrsAndValidate(Unknown Source)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.xerces.impl.dtd.XMLDTDValidator.handleStartElement(Unknown Source)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.xerces.impl.dtd.XMLDTDValidator.emptyElement(Unknown Source)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(<BR>Unknown Source)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at org.jdom.input.SAXBuilder.build(Unknown Source)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at org.jdom.input.SAXBuilder.build(Unknown Source)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at org.jdom.input.SAXBuilder.build(Unknown Source)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at net.sf.hibernate.tool.hbm2java.CodeGenerator.main(CodeGenerator.java:100)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at net.sf.hibernate.tool.hbm2java.Hbm2JavaTask.processFile(Hbm2JavaTask.java:149)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at net.sf.hibernate.tool.hbm2java.Hbm2JavaTask.execute(Hbm2JavaTask.java:97)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.tools.ant.Task.perform(Task.java:341)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.commons.jelly.tags.ant.AntTag.doTag(AntTag.java:185)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:233)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:89)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.maven.jelly.tags.werkz.MavenGoalTag.runBodyTag(MavenGoalTag.java:79)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.maven.jelly.tags.werkz.MavenGoalTag$MavenGoalAction.performAction(MavenGoalTag<BR>.java:110)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at com.werken.werkz.Goal.fire(Goal.java:639)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at com.werken.werkz.Goal.attain(Goal.java:575)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at com.werken.werkz.Goal.attainPrecursors(Goal.java:488)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at com.werken.werkz.Goal.attain(Goal.java:573)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.maven.plugin.PluginManager.attainGoals(PluginManager.java:671)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.maven.MavenSession.attainGoals(MavenSession.java:263)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.maven.cli.App.doMain(App.java:488)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at org.apache.maven.cli.App.main(App.java:1239)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at java.lang.reflect.Method.invoke(Method.java:324)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at com.werken.forehead.Forehead.run(Forehead.java:551)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; at com.werken.forehead.Forehead.main(Forehead.java:581)</P>
<P>build:<BR>----------------------------------<BR>----------------------------------<BR>solution : 升级hiberate verion 2.1.8<BR>----------------------------------<BR>----------------------------------<BR>改maven ：project.xml<BR>&lt;dependency&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;groupId&gt;hibernate&lt;/groupId&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;artifactId&gt;hibernate&lt;/artifactId&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;version&gt;2.1.8&lt;/version&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;properties&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&lt;ejb.manifest.classpath&gt;true&lt;/ejb.manifest.classpath&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;/properties&gt;<BR>&nbsp;&nbsp;&lt;/dependency&gt;<BR><BR>这样写，也是没有问题的<BR>&lt;discriminator type="java.lang.String" column="REGION_TYPE" length="10"/&gt;<BR><BR></P><img src ="http://www.blogjava.net/andyj2ee/aggbug/10504.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/andyj2ee/" target="_blank">java光环</a> 2005-08-19 13:52 <a href="http://www.blogjava.net/andyj2ee/archive/2005/08/19/10504.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>hiberante persistence</title><link>http://www.blogjava.net/andyj2ee/archive/2005/05/12/4238.html</link><dc:creator>java光环</dc:creator><author>java光环</author><pubDate>Thu, 12 May 2005 10:38:00 GMT</pubDate><guid>http://www.blogjava.net/andyj2ee/archive/2005/05/12/4238.html</guid><wfw:comment>http://www.blogjava.net/andyj2ee/comments/4238.html</wfw:comment><comments>http://www.blogjava.net/andyj2ee/archive/2005/05/12/4238.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/andyj2ee/comments/commentRss/4238.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/andyj2ee/services/trackbacks/4238.html</trackback:ping><description><![CDATA[<!--StartFragment --><!--StartFragment -->&nbsp;you had a table "miners" that looked like this&nbsp;<BR>
<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">create&nbsp;table&nbsp;miners&nbsp;(<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;id&nbsp;BIGINT&nbsp;NOT&nbsp;NULL&nbsp;AUTO_INCREMENT,<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;first_name&nbsp;VARCHAR(</SPAN><SPAN style="COLOR: #000000">255</SPAN><SPAN style="COLOR: #000000">),<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;last_name&nbsp;VARCHAR(</SPAN><SPAN style="COLOR: #000000">255</SPAN><SPAN style="COLOR: #000000">),<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;primary&nbsp;key&nbsp;(id)<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>)</SPAN></DIV></DIV>&nbsp;<BR>Hibernate class (Miner.java) specifies the fields, getters/setters and xdoclet tags looks like so. <BR>
<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;deadwood;<BR><IMG id=Codehighlighter1_18_59_Open_Image onclick="this.style.display='none'; Codehighlighter1_18_59_Open_Text.style.display='none'; Codehighlighter1_18_59_Closed_Image.style.display='inline'; Codehighlighter1_18_59_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_18_59_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_18_59_Closed_Text.style.display='none'; Codehighlighter1_18_59_Open_Image.style.display='inline'; Codehighlighter1_18_59_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN id=Codehighlighter1_18_59_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_18_59_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;@hibernate.class&nbsp;table="miners"<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_80_701_Open_Image onclick="this.style.display='none'; Codehighlighter1_80_701_Open_Text.style.display='none'; Codehighlighter1_80_701_Closed_Image.style.display='inline'; Codehighlighter1_80_701_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_80_701_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_80_701_Closed_Text.style.display='none'; Codehighlighter1_80_701_Open_Image.style.display='inline'; Codehighlighter1_80_701_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;Miner&nbsp;</SPAN><SPAN id=Codehighlighter1_80_701_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_80_701_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000">&nbsp;Long&nbsp;id;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000">&nbsp;String&nbsp;firstName;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000">&nbsp;String&nbsp;lastName;<BR><IMG id=Codehighlighter1_166_222_Open_Image onclick="this.style.display='none'; Codehighlighter1_166_222_Open_Text.style.display='none'; Codehighlighter1_166_222_Closed_Image.style.display='inline'; Codehighlighter1_166_222_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_166_222_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_166_222_Closed_Text.style.display='none'; Codehighlighter1_166_222_Open_Image.style.display='inline'; Codehighlighter1_166_222_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_166_222_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_166_222_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;&nbsp;&nbsp;&nbsp;*&nbsp;@hibernate.id&nbsp;generator-class="native"<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">*/</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_248_261_Open_Image onclick="this.style.display='none'; Codehighlighter1_248_261_Open_Text.style.display='none'; Codehighlighter1_248_261_Closed_Image.style.display='inline'; Codehighlighter1_248_261_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_248_261_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_248_261_Closed_Text.style.display='none'; Codehighlighter1_248_261_Open_Image.style.display='inline'; Codehighlighter1_248_261_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;Long&nbsp;getId()&nbsp;</SPAN><SPAN id=Codehighlighter1_248_261_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_248_261_Open_Text><SPAN style="COLOR: #000000">{&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;id;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_294_310_Open_Image onclick="this.style.display='none'; Codehighlighter1_294_310_Open_Text.style.display='none'; Codehighlighter1_294_310_Closed_Image.style.display='inline'; Codehighlighter1_294_310_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_294_310_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_294_310_Closed_Text.style.display='none'; Codehighlighter1_294_310_Open_Image.style.display='inline'; Codehighlighter1_294_310_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">void</SPAN><SPAN style="COLOR: #000000">&nbsp;setId(Long&nbsp;id)&nbsp;</SPAN><SPAN id=Codehighlighter1_294_310_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_294_310_Open_Text><SPAN style="COLOR: #000000">{&nbsp;</SPAN><SPAN style="COLOR: #0000ff">this</SPAN><SPAN style="COLOR: #000000">.id&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;id;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG id=Codehighlighter1_317_374_Open_Image onclick="this.style.display='none'; Codehighlighter1_317_374_Open_Text.style.display='none'; Codehighlighter1_317_374_Closed_Image.style.display='inline'; Codehighlighter1_317_374_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_317_374_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_317_374_Closed_Text.style.display='none'; Codehighlighter1_317_374_Open_Image.style.display='inline'; Codehighlighter1_317_374_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_317_374_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_317_374_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;&nbsp;&nbsp;&nbsp;*&nbsp;@hibernate.property&nbsp;column="first_name"<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">*/</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_409_429_Open_Image onclick="this.style.display='none'; Codehighlighter1_409_429_Open_Text.style.display='none'; Codehighlighter1_409_429_Closed_Image.style.display='inline'; Codehighlighter1_409_429_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_409_429_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_409_429_Closed_Text.style.display='none'; Codehighlighter1_409_429_Open_Image.style.display='inline'; Codehighlighter1_409_429_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;String&nbsp;getFirstName()&nbsp;</SPAN><SPAN id=Codehighlighter1_409_429_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_409_429_Open_Text><SPAN style="COLOR: #000000">{&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;firstName;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_478_508_Open_Image onclick="this.style.display='none'; Codehighlighter1_478_508_Open_Text.style.display='none'; Codehighlighter1_478_508_Closed_Image.style.display='inline'; Codehighlighter1_478_508_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_478_508_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_478_508_Closed_Text.style.display='none'; Codehighlighter1_478_508_Open_Image.style.display='inline'; Codehighlighter1_478_508_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">void</SPAN><SPAN style="COLOR: #000000">&nbsp;setFirstName(String&nbsp;firstName)&nbsp;</SPAN><SPAN id=Codehighlighter1_478_508_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_478_508_Open_Text><SPAN style="COLOR: #000000">{&nbsp;</SPAN><SPAN style="COLOR: #0000ff">this</SPAN><SPAN style="COLOR: #000000">.firstName&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;firstName;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG id=Codehighlighter1_515_571_Open_Image onclick="this.style.display='none'; Codehighlighter1_515_571_Open_Text.style.display='none'; Codehighlighter1_515_571_Closed_Image.style.display='inline'; Codehighlighter1_515_571_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_515_571_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_515_571_Closed_Text.style.display='none'; Codehighlighter1_515_571_Open_Image.style.display='inline'; Codehighlighter1_515_571_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_515_571_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_515_571_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;&nbsp;&nbsp;&nbsp;*&nbsp;@hibernate.property&nbsp;column="last_name"<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">*/</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_605_624_Open_Image onclick="this.style.display='none'; Codehighlighter1_605_624_Open_Text.style.display='none'; Codehighlighter1_605_624_Closed_Image.style.display='inline'; Codehighlighter1_605_624_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_605_624_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_605_624_Closed_Text.style.display='none'; Codehighlighter1_605_624_Open_Image.style.display='inline'; Codehighlighter1_605_624_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;String&nbsp;getLastName()&nbsp;</SPAN><SPAN id=Codehighlighter1_605_624_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_605_624_Open_Text><SPAN style="COLOR: #000000">{&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;lastName;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_671_699_Open_Image onclick="this.style.display='none'; Codehighlighter1_671_699_Open_Text.style.display='none'; Codehighlighter1_671_699_Closed_Image.style.display='inline'; Codehighlighter1_671_699_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_671_699_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_671_699_Closed_Text.style.display='none'; Codehighlighter1_671_699_Open_Image.style.display='inline'; Codehighlighter1_671_699_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">void</SPAN><SPAN style="COLOR: #000000">&nbsp;setLastName(String&nbsp;lastName)&nbsp;</SPAN><SPAN id=Codehighlighter1_671_699_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_671_699_Open_Text><SPAN style="COLOR: #000000">{&nbsp;</SPAN><SPAN style="COLOR: #0000ff">this</SPAN><SPAN style="COLOR: #000000">.lastName&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;lastName;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></SPAN></DIV></DIV><BR><!--StartFragment -->&nbsp;
<H2>Associations</H2>
<P><!--StartFragment -->&nbsp;the <U>Miner</U> class we looked at was single table oriented, mapping to a single <U>miners</U> table. ORM solutions support ways to map associated tables to in memory objects ,<BR><!--StartFragment -->&nbsp;</P>
<UL>
<LI>Many to One/One to one - belongs_to/has_one</LI>
<LI>One to Many (set) - has_many</LI>
<LI>Many to Many (set) - has_and_belongs_to_many</LI>
<LI>Single Table Inheritance</LI>
<LI>Components (mapping &gt; 1 object per table)</LI></UL>
<P><!--StartFragment -->&nbsp;As a comparative example, lets look at the many to one relationship. We are going to expand our Deadwood example from part I. We add to the <U>Miner</U> a many to one association with a <U>GoldClaim</U> object. This means there is a foreign key, gold_claim_id in the miners table, which links it to a row in the gold_claims table. <BR><BR></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">(Java)<BR><IMG id=Codehighlighter1_26_348_Open_Image onclick="this.style.display='none'; Codehighlighter1_26_348_Open_Text.style.display='none'; Codehighlighter1_26_348_Closed_Image.style.display='inline'; Codehighlighter1_26_348_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_26_348_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_26_348_Closed_Text.style.display='none'; Codehighlighter1_26_348_Open_Image.style.display='inline'; Codehighlighter1_26_348_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;Miner&nbsp;</SPAN><SPAN id=Codehighlighter1_26_348_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_26_348_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;Other&nbsp;fields/methods&nbsp;omitted</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000">&nbsp;GoldClaim&nbsp;goldClaim;<BR><IMG id=Codehighlighter1_101_194_Open_Image onclick="this.style.display='none'; Codehighlighter1_101_194_Open_Text.style.display='none'; Codehighlighter1_101_194_Closed_Image.style.display='inline'; Codehighlighter1_101_194_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_101_194_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_101_194_Closed_Text.style.display='none'; Codehighlighter1_101_194_Open_Image.style.display='inline'; Codehighlighter1_101_194_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_101_194_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_101_194_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;&nbsp;&nbsp;&nbsp;*&nbsp;@hibernate.many-to-one&nbsp;column="gold_claim_id"<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;cascade="save"<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">*/</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_232_252_Open_Image onclick="this.style.display='none'; Codehighlighter1_232_252_Open_Text.style.display='none'; Codehighlighter1_232_252_Closed_Image.style.display='inline'; Codehighlighter1_232_252_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_232_252_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_232_252_Closed_Text.style.display='none'; Codehighlighter1_232_252_Open_Image.style.display='inline'; Codehighlighter1_232_252_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;GoldClaim&nbsp;getGoldClaim()&nbsp;</SPAN><SPAN id=Codehighlighter1_232_252_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_232_252_Open_Text><SPAN style="COLOR: #000000">{&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;goldClaim;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_304_346_Open_Image onclick="this.style.display='none'; Codehighlighter1_304_346_Open_Text.style.display='none'; Codehighlighter1_304_346_Closed_Image.style.display='inline'; Codehighlighter1_304_346_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_304_346_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_304_346_Closed_Text.style.display='none'; Codehighlighter1_304_346_Open_Image.style.display='inline'; Codehighlighter1_304_346_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">void</SPAN><SPAN style="COLOR: #000000">&nbsp;setGoldClaim(GoldClaim&nbsp;goldClaim)&nbsp;</SPAN><SPAN id=Codehighlighter1_304_346_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_304_346_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: #0000ff">this</SPAN><SPAN style="COLOR: #000000">.goldClaim&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;goldClaim;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></SPAN></DIV></DIV><!--StartFragment --> Hibernate uses explicit mapping to specify the foreign key column, as well as the cascade behavior, which we will talk about next. Saving a <U>Miner</U> will save its associated <U>GoldClaim</U>, but updates and deletes to it won't affect the associated object. 
<P><!--StartFragment --><!--StartFragment -->&nbsp;<B>Transitive Persistence</B>&nbsp;&nbsp;<BR>Its important for an ORM solution to provide a way to detect and cascade changes from in memory objects to the database, without the need to manually <U>save()</U> each one. Hibernate features a flexible and powerful version of this via declarative cascading persistence.&nbsp;<BR><BR><!--StartFragment --> <B>Deleting</B> Hibernate offers a number of different cascading behaviors for all associations types, giving it a high degree of flexibility. For example, setting <U>cascade="all"</U> will make <U>GoldClaim</U> save, update and delete along with its parent <U>Miner</U>, like so... </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">Miner&nbsp;miner&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Miner();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>miner.setGoldClaim(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;GoldClaim());<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>session.save(miner);&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;Saves&nbsp;Miner&nbsp;and&nbsp;GoldClaim&nbsp;objects.</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">session.delete(miner);&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;Deletes&nbsp;both&nbsp;of&nbsp;them.</SPAN></DIV></DIV><!--StartFragment --> By using the cascade="save-update", you could get this behavior on any association, regardless of which table the foreign key lives in. Hibernate doesn't base the transistive persistence behavior off the relationship type, but rather the cascade style, which is much more fine grained and powerful.&nbsp;<BR><!--StartFragment --> 
<H2>Query Languages</H2>
<P><!--StartFragment -->&nbsp;Hibernate has its own object oriented query language (Hibernate Query Language - HQL), which is deliberately very similar to SQL. How it differs is that it lets developers express their queries in terms of objects and fields instead of tables and columns. Hibernate translates the query into SQL optimized for your particular database. Obviously, inventing a new query language is very substantial task, but the expressiveness and power of it is one of Hibernate's selling points.&nbsp;<BR><!--StartFragment --><BR> <B>Querying for Objects with HQL</B>&nbsp;<BR><!--StartFragment --> when you have to start navigating across objects with SQL, HQL can be very convenient alternative. Let's take a look at our sample queries for HQL. <BR></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: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;Find&nbsp;first&nbsp;Miner&nbsp;by&nbsp;name</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">Query&nbsp;q&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;session.createQuery(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">from&nbsp;Miner&nbsp;m&nbsp;where&nbsp;m.firstName&nbsp;=&nbsp;:name</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>q.setParameter(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">name</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Elma</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>Miner&nbsp;m&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;(Miner)&nbsp;q.setMaxResults(</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">).uniqueResult();<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: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;Finds&nbsp;up&nbsp;to&nbsp;10&nbsp;miners&nbsp;older&nbsp;than&nbsp;30,&nbsp;ordered&nbsp;by&nbsp;age.</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">Integer&nbsp;age&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Integer(</SPAN><SPAN style="COLOR: #000000">30</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>Query&nbsp;q&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;session.createQuery(<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">from&nbsp;Miner&nbsp;m&nbsp;where&nbsp;m.age&nbsp;&gt;&nbsp;:age&nbsp;order&nbsp;by&nbsp;age&nbsp;asc</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>List&nbsp;miners&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;q.setParameter(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">age</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;age).setMaxResults(</SPAN><SPAN style="COLOR: #000000">10</SPAN><SPAN style="COLOR: #000000">).list();<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: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;Similar&nbsp;to&nbsp;join&nbsp;query&nbsp;above,&nbsp;but&nbsp;no&nbsp;need&nbsp;to&nbsp;manually&nbsp;join</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">Query&nbsp;q&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;session.createQuery(<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">from&nbsp;Miner&nbsp;m&nbsp;where&nbsp;m.goldClaim.squareArea&nbsp;=&nbsp;:area</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>List&nbsp;minersWithSqA&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;q.setParameter(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">area</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Integer(</SPAN><SPAN style="COLOR: #000000">1000</SPAN><SPAN style="COLOR: #000000">)).list();</SPAN></DIV></DIV>
<P><!--StartFragment -->&nbsp;Having covered some of the basics of fetching objects, let's turn your attention to how we can make fetching objects fast. The next section covers the means by which we can tune the performance.&nbsp;<BR><!--StartFragment --> </P>
<H2>Performance Tuning</H2>
<P><!--StartFragment -->&nbsp;Beyond just mapping objects to tables, robust ORM solutions need to provide ways to tune the performance of the queries. One of the risks of working with ORM's is that you often pull back too much data from the database. This tends to happen because it its very easy to pull back several thousand rows, with multiple SQL queries, with a simple statement like <U>"from Miner"</U>. Common ORM strategies for dealing with this include Lazy fetching, outer join fetching and caching.&nbsp;<BR><BR><!--StartFragment --> What I mean by lazy is that when you fetch an object, the ORM tool doesn't fetch data from other tables, until you request the association. This prevents loading to much unneeded data.&nbsp;<!--StartFragment --> Hibernate allows you to choose which associations are lazy.&nbsp;<!--StartFragment --> This leads us to one of the great fallacies of ORM, that Lazy loading is always good. In reality, <B>lazy loading is only good if you didn't need the data</B>. Otherwise, you are doing with 2-1000+ queries what you could have done with one. This is dreaded N+1 select problem, where to get all the objects require N selects + 1 original selects. This problem gets much worse when you deal with collections.. </P>
<P><!--StartFragment --> <B>Outer Joins and Explicit Fetching</B> </P>
<P>Generally, one of the best way to improve performance is to limit the number of trips to the database. Better 1 big query than a few small ones. Hibernate has a number ways its handles the N+1 issue. Associations can be explicitly flagged for outer join fetching (via <U>outer-join="true"</U>), and you can add outer join fetching to HQL statements. For example...<BR><BR></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 id=Codehighlighter1_0_105_Open_Image onclick="this.style.display='none'; Codehighlighter1_0_105_Open_Text.style.display='none'; Codehighlighter1_0_105_Closed_Image.style.display='inline'; Codehighlighter1_0_105_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_0_105_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_0_105_Closed_Text.style.display='none'; Codehighlighter1_0_105_Open_Image.style.display='inline'; Codehighlighter1_0_105_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top><SPAN id=Codehighlighter1_0_105_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_0_105_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;@hibernate.many-to-one&nbsp;column="gold_claim_id"<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cascade="save-update"&nbsp;outer-join="true"<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top></SPAN><SPAN style="COLOR: #008000">*/</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_139_160_Open_Image onclick="this.style.display='none'; Codehighlighter1_139_160_Open_Text.style.display='none'; Codehighlighter1_139_160_Closed_Image.style.display='inline'; Codehighlighter1_139_160_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_139_160_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_139_160_Closed_Text.style.display='none'; Codehighlighter1_139_160_Open_Image.style.display='inline'; Codehighlighter1_139_160_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;GoldClaim&nbsp;getGoldClaim()&nbsp;</SPAN><SPAN id=Codehighlighter1_139_160_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_139_160_Open_Text><SPAN style="COLOR: #000000">{&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;goldClaim;&nbsp;&nbsp;}</SPAN></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: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;This&nbsp;does&nbsp;one&nbsp;select&nbsp;and&nbsp;fetches&nbsp;both&nbsp;the&nbsp;Miner&nbsp;and&nbsp;GoldClaim<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;and&nbsp;maps&nbsp;them&nbsp;correctly.</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">Miner&nbsp;m&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;(Miner)&nbsp;session.load(Miner.</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><SPAN style="COLOR: #000000">));</SPAN></DIV></DIV><!--StartFragment --> In addition, when selecting lists or dealing with collection associations, you can use an explicit outer join fetch, like so... <BR>
<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: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;Issues&nbsp;a&nbsp;single&nbsp;select,&nbsp;instead&nbsp;of&nbsp;1&nbsp;+&nbsp;N&nbsp;(where&nbsp;N&nbsp;is&nbsp;the&nbsp;#&nbsp;miners)</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">List&nbsp;list&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;session.find(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">from&nbsp;Miner&nbsp;m&nbsp;left&nbsp;join&nbsp;fetch&nbsp;m.goldClaim</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);</SPAN></DIV></DIV><!--StartFragment --> The performance savings from this can very significant.&nbsp;<BR><BR><!--StartFragment --> <B>Caching</B> 
<P>While object caching isn't always going to be helpful or a performance silver bullet, Hibernate has a huge potential advantage here. It provides several levels of caching, including a session (UnitOfWork) level as well as an optional second level cache. You always use the '1st level' cache, as it prevents circular references and multiple trips to the database for the same object. Using a second level cache can allow much of the database state to stay resident in memory. This is especially useful for frequently read and reference data.<BR></P><img src ="http://www.blogjava.net/andyj2ee/aggbug/4238.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/andyj2ee/" target="_blank">java光环</a> 2005-05-12 18:38 <a href="http://www.blogjava.net/andyj2ee/archive/2005/05/12/4238.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于cascade 与inverse</title><link>http://www.blogjava.net/andyj2ee/archive/2005/04/15/3313.html</link><dc:creator>java光环</dc:creator><author>java光环</author><pubDate>Fri, 15 Apr 2005 07:09:00 GMT</pubDate><guid>http://www.blogjava.net/andyj2ee/archive/2005/04/15/3313.html</guid><wfw:comment>http://www.blogjava.net/andyj2ee/comments/3313.html</wfw:comment><comments>http://www.blogjava.net/andyj2ee/archive/2005/04/15/3313.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/andyj2ee/comments/commentRss/3313.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/andyj2ee/services/trackbacks/3313.html</trackback:ping><description><![CDATA[<!--StartFragment -->看贴记录：<BR><BR>&nbsp;<SPAN class=postbody>在绝大多数（100%？）情况下，many-to-many的cascade都会设置为"save-update"， <BR>比如User和Role是many-to-many的，你不可能在删除一个Role时，把它的所有User都删除吧，反之也不可能。&nbsp;<BR><BR><!--StartFragment --> <SPAN class=postbody>双向的many-to-many维护起来确实比较麻烦，且效率可能比较低。 <BR>但我始终还是坚持一个原则：双向关联一定要一边设置为inverse="true"，更新时两边一起更新。我从来没有遇到过<SPAN style="FONT-WEIGHT: bold">违反外键</SPAN>的情况。</SPAN>&nbsp;<BR><BR><!--StartFragment --> <SPAN class=postbody>从关系本身来讲，一对多，多对一的关系本身都是由多的一方来维护的， <BR>多对多是由双方来维护的</SPAN> </SPAN><img src ="http://www.blogjava.net/andyj2ee/aggbug/3313.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/andyj2ee/" target="_blank">java光环</a> 2005-04-15 15:09 <a href="http://www.blogjava.net/andyj2ee/archive/2005/04/15/3313.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>