<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 http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<style>
<!--
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline;}
p
        {mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman";}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:Arial;
        color:windowtext;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
        {page:Section1;}
-->
</style>
</head>
<body lang=EN-US link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>Currently trying Pessimistic LockMode/Lock Options but this
results in a LockAcquisitionException. Ideally this would be blocking the
second thread trying to access the same record. Then when the first
thread releases lock the second would do its read and update. <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>EX:<o:p></o:p></span></font></p>
<p class=MsoNormal><span class=pbodypostablebody><font size=1 color="#333333"
face=Arial><span style='font-size:8.0pt;font-family:Arial;color:#333333'>We
have two threads that do a read. The first thread T1 appears to obtain
the lock.</span></font></span><font size=1 color="#333333" face=Arial><span
style='font-size:8.0pt;font-family:Arial;color:#333333'><o:p></o:p></span></font></p>
<p class=MsoNormal style='margin-bottom:12.0pt'><font size=1 color="#333333"
face=Arial><span style='font-size:8.0pt;font-family:Arial;color:#333333'><br>
<span class=pbodypostablebody>T1(l)----> t =
Session().get(this.getType(), id, new LockOptions(LockMode.PESSIMISTIC_READ));</span><br>
<span class=pbodypostablebody>T2(1)----> t2 =
Session().get(this.getType(), id, new LockOptions(LockMode.PESSIMISTIC_READ));</span><br>
<span class=pbodypostablebody>T2(2)----> dao.update(t2);</span><br>
<span class=pbodypostablebody>T2(3)----> t2.commit()
org.hibernate.exception.LockAcquisitionException: could not update: </span></span></font><span
class=pbodypostablebody><o:p></o:p></span></p>
<p class=MsoNormal style='margin-bottom:12.0pt;background:white'><span
class=pbodypostablebody><font size=1 color="#333333" face=Arial><span
style='font-size:8.0pt;font-family:Arial;color:#333333'>We want T2(1) to wait
until T1 is commited (versus blowing up). Here T2(1) appears to do a
dirty read of the object, and then throw an exception on commit T2(3). </span></font></span><o:p></o:p></p>
<p class=MsoNormal><span class=pbodypostablebody><font size=1 color="#333333"
face=Arial><span style='font-size:8.0pt;font-family:Arial;color:#333333'>Here
is our workaround, but we don't want to have to do this extra IO. Any
ideas on what to try?</span></font></span><font size=1 color="#333333"
face=Arial><span style='font-size:8.0pt;font-family:Arial;color:#333333'><br>
<br>
<span class=pbodypostablebody><i><span style='font-style:italic'>public T
read(PK id) {</span></i></span><i><span style='font-style:italic'><br>
<span class=pbodypostablebody> synchronized (LockingDao.class) {</span><br>
<span class=pbodypostablebody> t = session().get(class, id);
</span><br>
<span class=pbodypostablebody> MyObject myObj = (MyObject)
t;</span><br>
<span class=pbodypostablebody> myObj.setLastModDate(new
Date());</span><br>
<span class=pbodypostablebody> update(t); </span><br>
<span class=pbodypostablebody> getSession().flush();</span><br>
<span class=pbodypostablebody> return t;</span><br>
<span class=pbodypostablebody> }</span><br>
<span class=pbodypostablebody>}</span></span></i></span></font><font size=2
face=Arial><span style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></font></p>
<p><font size=2 face=Arial><span lang=EN style='font-size:10.0pt;font-family:
Arial'>Any insight is much appreciated,<o:p></o:p></span></font></p>
<p><font size=2 face=Arial><span lang=EN style='font-size:10.0pt;font-family:
Arial'>Sean </span></font><o:p></o:p></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p> </o:p></span></font></p>
</div>
</body>
</html>