Message:
A new issue has been created in JIRA.
---------------------------------------------------------------------
View the issue:
http://opensource.atlassian.com/projects/hibernate/secure/ViewIssue.jspa?key=HB-106
Here is an overview of the issue:
---------------------------------------------------------------------
Key: HB-106
Summary: Minor flaw in suggested error handling
Type: Bug
Status: Unassigned
Priority: Trivial
Project: Hibernate2
Versions:
2.0rc2
Assignee:
Reporter: Paul Rivers
Created: Sun, 25 May 2003 4:42 PM
Updated: Sun, 25 May 2003 4:42 PM
Environment: irrelevant
Description:
I wasn't sure where to put a documentation issue, I thought this would be the best place. Please let me know if this is incorrect, and I'll post elsewhere in the future.
In "6.9.4. Exception handling" in the documentation, the first exception handling idiom is recommended:
Session sess = factory.openSession();
Transaction tx = null;
try {
tx = sess.beginTransaction();
// do some work
...
tx.commit();
}
catch (Exception e) {
if (tx!=null) tx.rollback();
throw e;
}
finally {
sess.close();
}
However, notice the "catch (Exception e) {" line. If a RuntimeException is thrown, the catch block will never be entered, and the transaction will never be terminated. Thus that line should be replaced by "catch (Throwable e) {" so that the entire example will read:
Session sess = factory.openSession();
Transaction tx = null;
try {
tx = sess.beginTransaction();
// do some work
...
tx.commit();
}
catch (Throwable e) {
if (tx!=null) tx.rollback();
throw e;
}
finally {
sess.close();
}
This also applies to the next 2 examples in the documentation.
---------------------------------------------------------------------
JIRA INFORMATION:
This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/Administrators.jspa
If you want more information on JIRA, or have a bug to report see:
http://www.atlassian.com/software/jira
|