/
2905.html
210 lines (178 loc) · 17.4 KB
/
2905.html
1
<html xmlns:o="urn:schemas-microsoft-com:office:office"xmlns:w="urn:schemas-microsoft-com:office:word"xmlns="http://www.w3.org/TR/REC-html40"><head><meta name=Title content="Errata "><meta name=Keywords content=""><meta http-equiv=Content-Type content="text/html; charset=macintosh"><meta name=ProgId content=Word.Document><meta name=Generator content="Microsoft Word 11"><meta name=Originator content="Microsoft Word 11"><link rel=File-List href="511-4%20Errata_files/filelist.xml"><title>Errata </title><!--[if gte mso 9]><xml> <o:DocumentProperties> <o:Author>Nicole Faraclas</o:Author> <o:Template>Normal</o:Template> <o:LastAuthor>Richard Ables</o:LastAuthor> <o:Revision>2</o:Revision> <o:TotalTime>1</o:TotalTime> <o:Created>2006-06-23T21:37:00Z</o:Created> <o:LastSaved>2006-06-23T21:37:00Z</o:LastSaved> <o:Pages>3</o:Pages> <o:Words>579</o:Words> <o:Characters>3305</o:Characters> <o:Company>Apress</o:Company> <o:Lines>27</o:Lines> <o:Paragraphs>6</o:Paragraphs> <o:CharactersWithSpaces>4058</o:CharactersWithSpaces> <o:Version>11.0</o:Version> </o:DocumentProperties> <o:OfficeDocumentSettings> <o:PixelsPerInch>96</o:PixelsPerInch> <o:TargetScreenSize>800x600</o:TargetScreenSize> </o:OfficeDocumentSettings></xml><![endif]--><!--[if gte mso 9]><xml> <w:WordDocument> <w:Zoom>125</w:Zoom> <w:PunctuationKerning/> </w:WordDocument></xml><![endif]--><style><!-- /* Font Definitions */@font-face {font-family:"Times New Roman"; panose-1:0 2 2 6 3 5 4 5 2 3; mso-font-charset:0; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:50331648 0 0 0 1 0;}@font-face {font-family:Arial; panose-1:0 2 11 6 4 2 2 2 2 2; mso-font-charset:0; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:50331648 0 0 0 1 0;}@font-face {font-family:"Courier New"; panose-1:0 2 7 3 9 2 2 5 2 4; mso-font-charset:0; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:50331648 0 0 0 1 0;} /* Style Definitions */p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman";}h1 {margin-right:0in; mso-margin-top-alt:auto; mso-margin-bottom-alt:auto; margin-left:0in; mso-pagination:widow-orphan; mso-outline-level:1; font-size:24.0pt; font-family:"Times New Roman"; mso-font-kerning:18.0pt; font-weight:bold;}h2 {mso-style-next:Normal; margin-top:12.0pt; margin-right:0in; margin-bottom:3.0pt; margin-left:0in; mso-pagination:widow-orphan; page-break-after:avoid; mso-outline-level:2; font-size:14.0pt; font-family:Arial; font-weight:bold; font-style:italic;}p {margin-right:0in; mso-margin-top-alt:auto; mso-margin-bottom-alt:auto; margin-left:0in; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman";}pre {margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; font-size:10.0pt; font-family:"Courier New";}table.MsoNormalTable {mso-style-parent:""; font-size:10.0pt; font-family:"Times New Roman";}@page Section1 {size:8.5in 11.0in; margin:1.0in 1.25in 1.0in 1.25in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;}div.Section1 {page:Section1;}--></style></head><body bgcolor=white lang=EN-US style='tab-interval:.5in'><div class=Section1><p class=MsoNormal>Errata </p><p class=MsoNormal>Pro Hibernate 3</p><p class=MsoNormal>1590595114</p><p class=MsoNormal>Dave Minter</p><p class=MsoNormal>Jeff Linwood</p><p class=MsoNormal><![if !supportEmptyParas]> <![endif]><o:p></o:p></p><h1>Chapter 3</h1><p>In the code example of listing 3-22 on page 53, the access qualifier isincorrectly stated as "protected" when it should be"public".</p><p>The corrected listing is as follows:</p><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre>package com.hibernatebook.chapter3.dao;</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre>import java.util.logging.Logger;</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><b>public</b><spanstyle='font-weight:normal'> class DAO {</span></pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>public DAO() {</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>}</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>public static final Logger log = Logger.getAnonymousLogger();</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre>}</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><p><i>Note: The downlodable sample is correct</i></p><h1>Chapter 9</h1><h2>Deadlocks pp164 - 170</h2><p>There are two serious bugs in the example. Please note that these are <u>notcaused by Hibernate</u> itself, which is behaving entirely as specified.</p><p>The symptoms are that the example will not necessarily deadlock, and mayleave the database in an inconsistent state.</p><p>Firstly we did not correctly set the level of isolation in the example. Wehave amended the run method of the GenerateDeadlock class as follows to correctthis problem:</p><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>public void run() {</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>Session session = sessions.openSession();</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span><span style="mso-spacerun: yes"> </span>Transaction tx = null;</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>try {</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span><b>// Set serialization level.<o:p></o:p></b></pre><pre><b><![if !supportEmptyParas]> <![endif]><o:p></o:p></b></pre><pre><b><span style="mso-spacerun: yes"> </span>session.connection().setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);</b></pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>System.out.println(taskName + " begins a transaction.");</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>tx = session.beginTransaction();</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>// Step 1</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>System.out.println(taskName + " step 1");</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>step1(session);</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>System.out.println(taskName + " step 1 done");</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>// Pause to ensure proper ordering</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>// of the steps. You would never</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>// normally do this - however, for our</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>// purposes it prevents either transaction</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>// from completing before the other has</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>// got under way (which would prevent the</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>// deadlock from arising).</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>pause();</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>// Step 2</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>System.out.println(taskName + " step 2");</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>step2(session);</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>System.out.println(taskName + " step 2 done");</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span><span style="mso-spacerun: yes"> </span>System.out.println(taskName + " committing");</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>tx.commit();</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>System.out.println(taskName + " committed");</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>tx = null;</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>} catch (Exception e) {</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><spanstyle='mso-tab-count:3'> </span>e.printStackTrace();</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>if (tx != null)</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span><span style="mso-spacerun: yes"> </span>tx.rollback();</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>System.out.println(taskName</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>+ " rolled back its transaction: " + e);</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>} finally {</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>System.out.println("Session for " + taskName + " closed.");</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>session.close();</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span><span style="mso-spacerun: yes"> </span>}</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span>}</pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><p><i>Note that in the above we have also removed a superfluous call to theflush() method.</i></p><p>Secondly we failed to take into account one of the idiosyncracies of the Antbuild tool. By default the Ant <java ... /> task kicks off the codein-thread. While this has performance advantages on large builds, it does meanthat Ant only waits for the termination of the thread it started, not that ofany daughter threads.</p><p>The task may therefore be considered to be "complete" before anyprocessing in daughter threads has finished. When Ant terminates, any daughterthreads are then killed without ceremony. The easiest way to fix this issue isto append the fork="true" attribute to the task in question thus:</p><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><!-- Run the connected deadlock example --></pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><target name="deadlock" depends="dist"></pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span><java classname="com.hibernatebook.chapter09.deadlock.GenerateDeadlock" classpathref="classpath.run" <b>fork="true"</b><spanstyle='font-weight:normal'>></span></pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span><arg value="42"/></pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre><span style="mso-spacerun: yes"> </span></java></pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><pre></target></pre><pre><![if !supportEmptyParas]> <![endif]><o:p></o:p></pre><p>This forces Ant to start the task in a new JVM process. The normal threadtermination rules will then be obeyed, and Ant will only proceed with the nextbuild task (or exit) when the forked JVM process terminates.</p><h1>Chapter 3</h1><p>Chapter 3 does not explicitly include the appropriate mapping file(Motd.hbm.xml) for the "Message Of the Day" application</p><p>The text of this file is in fact given verbatim in Chapter 1 on pp 9 - 10,or can be downloaded with the example files for Chapter 3</p><p class=MsoNormal><![if !supportEmptyParas]> <![endif]><o:p></o:p></p></div></body></html>