<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7652.24">
<TITLE>Hibernate + Oracle RDB 7.1</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->
<P><FONT SIZE=2 FACE="Verdana">Hi,</FONT>
</P>
<P><FONT SIZE=2 FACE="Verdana">We have discovered a minor problem within JDBCtransaction.java when using Oracle RDB 7.1, </FONT>
<BR><FONT SIZE=2 FACE="Verdana">the database transaction is not automatically rollbacked by the database on commit failures, </FONT>
<BR><FONT SIZE=2 FACE="Verdana">the client has to send a rollback over the JDBC-connection in that case. When no rollback is sent, </FONT>
<BR><FONT SIZE=2 FACE="Verdana">the database transaction will still be open and associated with a JDBC-connection when the connection is returned </FONT>
<BR><FONT SIZE=2 FACE="Verdana">to the connection pool. At another time some other client transaction will get this connection from the pool with </FONT>
<BR><FONT SIZE=2 FACE="Verdana">an open database transaction which then will fail. We have solved this problem by changing JDBCTransaction in this way:</FONT>
</P>
<P> <FONT SIZE=2 FACE="Verdana">private boolean rollbackAfterCommitFailed = false;</FONT>
</P>
<P> <FONT SIZE=2 FACE="Verdana">public void setRollbackAfterCommitFailed(boolean rollbackAfterCommitFailed) {</FONT>
<BR> <FONT SIZE=2 FACE="Verdana">this.rollbackAfterCommitFailed = rollbackAfterCommitFailed;</FONT>
<BR> <FONT SIZE=2 FACE="Verdana">}</FONT>
</P>
<P> <FONT SIZE=2 FACE="Verdana">private void commitAndResetAutoCommit() throws SQLException {</FONT>
<BR> <FONT SIZE=2 FACE="Verdana">try {</FONT>
<BR> <FONT SIZE=2 FACE="Verdana">jdbcContext.connection().commit(); </FONT>
<BR> <FONT SIZE=2 FACE="Verdana">} catch (SQLException e) {</FONT>
<BR> <FONT SIZE=2 FACE="Verdana">// Extension for Oracle-RDB: Rollback after failed Commit</FONT>
<BR> <FONT SIZE=2 FACE="Verdana">if (rollbackAfterCommitFailed) {</FONT>
<BR> <FONT SIZE=2 FACE="Verdana">try {</FONT>
<BR> <FONT SIZE=2 FACE="Verdana">log.error("Rollback after Commit-Failure");</FONT>
<BR> <FONT SIZE=2 FACE="Verdana">jdbcContext.connection().rollback();</FONT>
<BR> <FONT SIZE=2 FACE="Verdana">} catch (SQLException s) {</FONT>
<BR> <FONT SIZE=2 FACE="Verdana">log.error("Exception during Rollback", s);</FONT>
<BR> <FONT SIZE=2 FACE="Verdana">}</FONT>
<BR> <FONT SIZE=2 FACE="Verdana">throw e;</FONT>
<BR> <FONT SIZE=2 FACE="Verdana">}</FONT>
<BR> <FONT SIZE=2 FACE="Verdana">finally {</FONT>
<BR> <FONT SIZE=2 FACE="Verdana">toggleAutoCommit();</FONT>
<BR> <FONT SIZE=2 FACE="Verdana">}</FONT>
<BR> <FONT SIZE=2 FACE="Verdana">}</FONT>
</P>
<P><FONT SIZE=2 FACE="Verdana">In the JDBCTransactionFactory we added following:</FONT>
</P>
<P><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> private boolean rollbackCommitFailures;</FONT><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> // Property hibernate.transaction.rollback_after_commit_failure</FONT>
</P>
<P><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> public Transaction createTransaction(JDBCContext jdbcContext,</FONT>
<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> Context transactionContext) throws HibernateException {</FONT>
<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> JDBCTransaction trans = new JDBCTransaction(jdbcContext, transactionContext);</FONT>
<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> trans.setRollbackAfterCommitFailed(rollbackCommitFailures);</FONT>
<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> return trans;</FONT>
<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> }</FONT>
</P>
<P><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> /** {@inheritDoc} */</FONT>
<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> public void configure(Properties props) throws HibernateException {</FONT>
</P>
<P><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> rollbackCommitFailures = PropertiesHelper.getBoolean(</FONT>
<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> Environment.TRANSACTION_</FONT><FONT COLOR="#000000" SIZE=2 FACE="Courier New">ROLLBACK_COMMIT_FAILURES</FONT><FONT COLOR="#000000" SIZE=2 FACE="Courier New">, props,false);</FONT>
<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> </FONT>
<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> }</FONT>
</P>
<P><FONT COLOR="#000000" SIZE=2 FACE="Courier New">It would be nice to have this little problem solved in future Hibernate releases.</FONT>
<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">I also really would like to see Oracle RDB in the list of supported databases, for every new </FONT>
<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">Hibernate Release I have to compile/add RdbDialect.java (got it from HP/Oracle) to the jar. </FONT>
</P>
<BR>
<P><FONT COLOR="#000000" SIZE=2 FACE="Courier New">Regards</FONT>
</P>
<P><FONT COLOR="#000000" SIZE=2 FACE="Courier New">Martin</FONT>
</P>
<pre>
Oesterreichische Lotterien Gesellschaft m.b.H., Rennweg 44, A-1038 Wien,
FN 54472 g, Handelsgericht Wien, DVR-Nr: 0476706
</pre></BODY>
</HTML>