ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tony Qian" <daqiqi...@aol.com>
Subject Re: Rollback Issues
Date Fri, 16 Jun 2006 17:05:56 GMT
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title></title>
</head>
<body>
<font face="Arial,sans-serif"><font size="2">Jeff,<br>
<br>
I didn't see </font></font><font face="Arial,sans-serif" size="2">commitRequired
attribute is mentioned in the iBATIS document. If I set </font><font  face="Arial,sans-serif"
size="2">commitRequired="true" , does it have
any effect on daoManager?</font><br>
<font face="Arial,sans-serif"><font size="2"><br>
btw, is it possible to add following code to java bean object generated
by Abator so that we can easily log java bean in debug log file etc. ?<br>
<br>
import org.apache.commons.lang.builder.*;<br>
<br>
<br>
&nbsp;&nbsp; public String toString() {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return ReflectionToStringBuilder.toString(this);<br>
&nbsp;&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp;&nbsp; public boolean equals(Object o) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return EqualsBuilder.reflectionEquals(this,
o);<br>
&nbsp;&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp;&nbsp; public int hashCode() {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return HashCodeBuilder.reflectionHashCode(this);<br>
&nbsp;&nbsp;&nbsp; }<br>
<br>
<br>
thanks,<br>
Tony<br>
<br>
<br>
<span type="cite">Jeff Butler wrote on 6/15/2006, 1:51 PM:</span>
</font></font>
<p><font face="Arial,sans-serif" size="2"></font></p>
<blockquote type="cite"  style="border-left: thin solid blue; padding-left: 10px; margin-left:
0pt;"><font  face="Arial,sans-serif" size="2"></font>
  <div><font face="Arial,sans-serif" size="2">Tony - this is something
iBATIS is doing to try to help you (Ha Ha).&nbsp; By default iBATIS will&nbsp;not
commit after a queryForObject or queryForList - even if you explictely
call the commitTransaction() method.&nbsp; The solution is to add the
attribute commitRequired="true" to the transactionManager element in
your SqlMapConfig.xml file.</font></div>
  <font face="Arial,sans-serif" size="2"></font>
  <div><font face="Arial,sans-serif" size="2">&nbsp;</font></div>
  <font face="Arial,sans-serif" size="2"></font>
  <div><font face="Arial,sans-serif" size="2">Jeff Butler<br>
  <br>
&nbsp;</font></div>
  <font face="Arial,sans-serif" size="2"></font>
  <div><font face="Arial,sans-serif" size="2"><span class="gmail_quote">On
6/15/06, <b class="gmail_sendername">Tony Qian</b> &lt;<a  href="mailto:daqiqian2@aol.com">daqiqian2@aol.com</a>&gt;
wrote:</span>
  </font>
  <blockquote class="gmail_quote"  style="border-left: 1px solid rgb(204, 204, 204); margin:
0px 0px 0px 0.8ex; padding-left: 1ex;"><font  face="Arial,sans-serif" size="2"></font>
    <div><font face="Arial,sans-serif" size="2"></font>
    <div><font face="Arial,sans-serif" size="2"><font size="2">Jeff,<br>
    <br>
Since you mentioned stored procedure and transaction, I have
encountered a strange situation when using MySQL stored procedure. In
my stored procedure, I do some update to the records in a table then
select all those rows get updated. In my Dao, I call QueryForList to
retrieve the records. Everything works perfectly fine ( I got correct
result set) until I went to database and found that all updates were
not committed. I have to commit the update in my stored procedure.
    <br>
    <br>
Is it true that all QueryForList or QueryForObject will NOT do commit?
That makes sense for 'regular query'. But, we can combine anything
inside stored procedure. This is not correct behavior. One way to solve
this problem is to use </font></font><font face="Arial,sans-serif"  size="2"><span><span><span><span><font
face="Arial,sans-serif" size="2">daoManager.startTransaction
() etc. to force commit. I haven't tried that yet. Don't know if it
will work. <br>
    <br>
Thanks,<br>
Tony<br>
    </font></span></span></span></span></font><font
 face="Arial,sans-serif" size="2"><font size="2"><br>
    <span type="cite">Jeff Butler wrote on 6/15/2006, 1:14 PM:</span> </font></font></div>
    <font face="Arial,sans-serif" size="2"></font>
    <div><font face="Arial,sans-serif" size="2"><span class="e"  id="q_10bd8c76f4d1ebc4_1">
    <blockquote  style="border-left: thin solid blue; padding-left: 10px; margin-left:
0pt;"  type="cite">
      <div><font face="Arial,sans-serif" size="2">The plot thickens...</font></div>
      <div><font face="Arial,sans-serif" size="2">&nbsp;</font></div>
      <div><font face="Arial,sans-serif" size="2">I seem to remember
that there is something unusual with Oracle&nbsp;stored procedures and
transactions.&nbsp; Sounds to me like the stored procedure call is causing a
commit somehow.&nbsp; You could try some other combination of statements
without a SP call just to check.&nbsp; I'm not an Oracle person so maybe
someone else could jump in who's had some experience with stored
procedures and transactions in Oracle. </font></div>
      <div><font face="Arial,sans-serif" size="2">&nbsp;</font></div>
      <div><font face="Arial,sans-serif" size="2">Also, what I meant
from question 2 was this - what is the actual exception you are seeing
at runtime that bypasses the commit?&nbsp; Maybe there is some useful
information in that exception?
      </font></div>
      <div><font face="Arial,sans-serif" size="2">&nbsp;</font></div>
      <div><font face="Arial,sans-serif" size="2">Jeff Butler<br>
      <br>
&nbsp;</font></div>
      <div><font face="Arial,sans-serif" size="2"><span  class="gmail_quote">On
6/15/06, <b class="gmail_sendername">Debasish
Dutta Roy</b> &lt;<a  onclick="return top.js.OpenExtLink(window,event,this)"
 href="mailto:debasish.duttaroy@gmail.com" target="_blank">
debasish.duttaroy@gmail.com</a>&gt; wrote:</span> </font>
      <blockquote class="gmail_quote"  style="border-left: 1px solid rgb(204, 204, 204);
margin: 0px 0px 0px 0.8ex; padding-left: 1ex;">
        <div><font face="Arial,sans-serif" size="2">OK. Here are the
answers<br>
        <br>
1. First one is an insert &amp; second one is a stored proc call. The
first one populates the REQUEST table and the second one gets a number
based on the request id.
        <br>
2. Dao1 and DAO2 catches SQLException and throws DAOException (my
exception, not iBATIS DAOException). <br>
&nbsp;&nbsp;&nbsp; This DAOException is caught in the catch block and thrown as
a
business exception. say RequestFailureException
        <br>
3. Sampling from my dao.xml</font></div>
        <div><font face="Arial,sans-serif" size="2"><span><br>
        <br>
&nbsp;&nbsp;&nbsp; &lt;context&gt;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;transactionManager type="SQLMAP"&gt;
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&lt;property name="SqlMapConfigResource" value="xml/sql-
map-config.xml"/&gt; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/transactionManager&gt;<br>
        <br>
        </span></font></div>
        <div><font face="Arial,sans-serif" size="2">&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &lt;!-- DAO
declarations --&gt;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;dao interface=" com.novartis.phoenix.db.dao.RequestDAO"<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
implementation="com.mydao.sqlmap.SqlMapRequestDAOImpl
"/&gt;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;dao interface=" com.novartis.phoenix.db.dao.GOSDAO"<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
implementation=" com.mydao.sqlmap.SqlMapGOSDAOImpl"/&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp; .......................<br>
&nbsp;&nbsp;&nbsp; &lt;/context&gt;
        <br>
        <br>
Hope this will help.</font></div>
        <div><font face="Arial,sans-serif" size="2"><span><br>
        <br>
        <div><span class="gmail_quote">On 6/15/06, <b  class="gmail_sendername">Jeff
Butler</b> &lt;<a  onclick="return top.js.OpenExtLink(window,event,this)"  href="mailto:jeffgbutler@gmail.com"
target="_blank">jeffgbutler@gmail.com
        </a>&gt; wrote:</span>
        <blockquote class="gmail_quote"  style="border-left: 1px solid rgb(204, 204, 204);
margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
          <div>
          <div>I think we need a little more information.&nbsp; I assume
that the code you've prsented is a mocked up example - and everything
looks right in your mock up.</div>
          <div>&nbsp;</div>
          <div>Questions:</div>
          <div>&nbsp;</div>
          <div>1. What is the method secondTask() doing?&nbsp; Hopefully no
transaction stuff (like another start transaction or a commit).</div>
          <div>2. What Exception is thrown from secondTask()?</div>
          <div>3. By any chance, are DAO1 and DAO2 in different
&lt;context&gt; elements in your dao.xml?&nbsp; From your mocked up code it
doesn't look like they are, but also doesn't hurt to ask.</div>
          </div>
          <div><span>
          <div>&nbsp;</div>
          <div>Jeff Butler</div>
          </span></div>
          <div><span>
          <div>&nbsp;</div>
          <div><br>
          <br>
&nbsp;</div>
          <div><span class="gmail_quote">On 6/15/06, <b  class="gmail_sendername">Debasish
Dutta Roy</b> &lt;<a  onclick="return top.js.OpenExtLink(window,event,this)"
 href="mailto:debasish.duttaroy@gmail.com" target="_blank">debasish.duttaroy@gmail.com
          </a>&gt; wrote:</span>
          <blockquote class="gmail_quote"  style="border-left: 1px solid rgb(204, 204,
204); margin: 0px 0px 0px 0.8ex; padding-left: 1ex;">
            <div>offcourse it will be helpful if you could share what
you did correctly, and if you could find something wrong in my
approach. I am using Oracle 9i.</div>
            <div><span><br>
            <br>
            <div><span class="gmail_quote">On 6/15/06, <b  class="gmail_sendername">Tony
Qian</b> &lt;<a  onclick="return top.js.OpenExtLink(window,event,this)"  href="mailto:daqiqian2@aol.com"
target="_blank">daqiqian2@aol.com</a>&gt;
wrote: </span>
            <blockquote class="gmail_quote"  style="border-left: 1px solid rgb(204, 204,
204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
              <div>
              <div><font face="Arial,sans-serif"><font size="2">Yes. It
worked for me (MySQL).<br>
              <br>
Tony<br>
              <br>
              <span type="cite">Debasish Dutta Roy wrote on 6/15/2006,
11:09 AM:</span> </font></font></div>
              <div><span>
              <blockquote  style="border-left: thin solid blue; padding-left: 10px; margin-left:
0pt;"  type="cite"><font face="Arial,sans-serif" size="2">Hi All<br>
Has anyone successfully tested rollback with DAOManager implementation.
                <br>
                <br>
I am unable to get it working.<br>
                <br>
                <br>
I have a business delegate who does like this:<br>
                <br>
DAO1 dao1 = daoManager.getDAO(DAO1.class);<br>
DAO2 dao2 = daoManager.getDAO(DAO2.class);<br>
try { <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; daoManager.startTransaction ();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dao1.firstTask();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dao2.secondTask();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; daoManager.commitTransaction();<br>
} catch (Exception e) {<br>
&nbsp;&nbsp; throw myException;<br>
} finally {<br>
&nbsp;&nbsp; daoManager.endTransaction ();<br>
}<br>
                <br>
                <br>
my dao.xml is like this<br>
                <br>
&nbsp;&nbsp;&nbsp; &lt;context&gt;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;transactionManager type="SQLMAP"&gt;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&lt;property name="SqlMapConfigResource"
value="xml/sql-map-config.xml "/&gt; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/transactionManager&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp; ...........<br>
&nbsp;&nbsp;&nbsp;&nbsp; ...........<br>
&nbsp;&nbsp; &lt;/context&gt;<br>
                <br>
and the corresponding sql-map-config.xml<br>
                <br>
&lt;sqlMapConfig&gt;<br>
                <br>
&nbsp;&nbsp;&nbsp; &lt;transactionManager type="JDBC" commitRequired="true"&gt;
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;dataSource type="JNDI"&gt;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&lt;property name="DataSource" value="<a>java:comp/env/jdbc</a></font>
                <div><font face="Arial,sans-serif" size="2">/MyDataSource"/&gt;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/dataSource&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;/transactionManager&gt; <br>
                </font></div>
              </blockquote>
              </span></div>
              </div>
            </blockquote>
            </div>
            <br>
            </span></div>
          </blockquote>
          </div>
          <br>
          </span></div>
        </blockquote>
        </div>
        <br>
        </span></font></div>
      </blockquote>
      </div>
      <font face="Arial,sans-serif" size="2"><br>
      </font></blockquote>
    </span></font></div>
    <font face="Arial,sans-serif" size="2"></font></div>
  </blockquote>
  </div>
  <font face="Arial,sans-serif" size="2"><br>
  </font></blockquote>
</body>
</html>


Mime
View raw message