X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 96B75D1B18A for ; Sun, 1 Aug 2004 18:22:31 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 65092-08 for ; Sun, 1 Aug 2004 21:22:32 +0000 (GMT) Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [203.79.85.162]) by svr1.postgresql.org (Postfix) with ESMTP id 9CADFD1B16D for ; Sun, 1 Aug 2004 18:22:28 -0300 (ADT) Received: from 203-79-104-60.cable.paradise.net.nz ([203.79.104.60] helo=opencloud.com) by yass.opencloud.co.nz with asmtp (Exim 3.35 #1 (Debian)) id 1BrNmZ-0005DD-00; Mon, 02 Aug 2004 09:22:15 +1200 Message-ID: <410D5F04.3010903@opencloud.com> Date: Mon, 02 Aug 2004 09:22:12 +1200 From: Oliver Jowett User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6b) Gecko/20031205 Thunderbird/0.4 X-Accept-Language: en-us, en MIME-Version: 1.0 To: "Vianen, Jeroen van" Cc: pgsql-jdbc@postgresql.org Subject: Re: PostgreSQL JDBC + Hibernate lose valuable debug info if References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.1 tagged_above=0.0 required=5.0 tests=RCVD_IN_SORBS X-Spam-Level: X-Archive-Number: 200408/4 X-Sequence-Number: 10726 Vianen, Jeroen van wrote: > Hi, > > When using Hibernate together with PostgreSQL the following might happen: > > - Hibernate uses batched updates > - An exception is thrown (e.g. when a foreign key constraint is violated or > a not null column is left out, etc.) > - This SQLException is wrapped in a PBatchUpdateException > - This PBatchUpdateException is wrapped in a HibernateException > - The HibernateException is written to the log > > The problem is that Hibernate uses standard stacktrace print routines with > Root causes as found in JDK 1.4. The call on getNextException() as found in > SQLException is never made and valuable debugging information is lost, e.g. > the actual cause of the BatchUpdateException. > > I am wondering whether it is possible to mimic JDK 1.4 root cause exception > handling in PBatchUpdateException so a decent stack trace can be logged. It's not instantly clear how this should be structured. There might be multiple SQL exceptions generated, but they are not necessarily causes of each other. How about something like: PBE instanceof PBatchUpdateException PBE.getNextException() == E1 PBE.getCause() == E1 E1 instanceof SQLException E1.getNextException() == E2 E1.getCause() == null (or actual cause of E1) E2 instanceof SQLException E2.getNextException() == E3 E2.getCause() == null (or actual cause of E2) ... etc ... i.e. you don't get all exceptions chained via 1.4-style getCause(), but the BatchUpdateException's cause points to the first exception in the chain of actual exceptions. pre-1.4 clients can still get access to the underlying exception from the BatchUpdateException by walking the SQL exception chain as usual. Note that if Hibernate isn't walking the exception chain, you may be losing information anyway even when batch exceptions are not involved -- if there is more than one exception generated they are not linked via the 1.4 mechanism (deliberately, as each exception in the chain might have an independent cause such as an IOException). So Hibernate probably needs fixing too :) -O