Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 561FC1337B79 for ; Tue, 18 Jan 2011 18:46:24 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 16892-04 for ; Tue, 18 Jan 2011 22:46:17 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from lo.gmane.org (lo.gmane.org [80.91.229.12]) by mail.postgresql.org (Postfix) with ESMTP id C67D613364DE for ; Tue, 18 Jan 2011 18:46:16 -0400 (AST) Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1PfKJZ-0007er-SN for pgsql-jdbc@postgresql.org; Tue, 18 Jan 2011 23:46:13 +0100 Received: from 217.110.94.67 ([217.110.94.67]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 18 Jan 2011 23:46:13 +0100 Received: from spam_eater by 217.110.94.67 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 18 Jan 2011 23:46:13 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-jdbc@postgresql.org From: Thomas Kellerer Subject: Re: jdbc spec violation for autocommit=true & addbatch/executeBatch Date: Tue, 18 Jan 2011 23:45:59 +0100 Lines: 47 Message-ID: References: <4D3606CD.7080707@opencloud.com> <728504.34967.qm@web33202.mail.mud.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: 217.110.94.67 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 In-Reply-To: <728504.34967.qm@web33202.mail.mud.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.735 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_NUMERIC_HELO=1.164, T_RP_MATCHES_RCVD=-0.01, T_TO_NO_BRKTS_FREEMAIL=0.01 X-Spam-Level: X-Archive-Number: 201101/56 X-Sequence-Number: 21388 Quartz, 18.01.2011 22:55: > This is very sad. The batch never mean transaction. It happens to be > the supporting fixture for the transaction, but also to avoid > roundtrips with connection pools and such overhead when not using > transaction as autocommit=true suggest. The JDBC Specification (jdbc-4.0-fr-spec.pdf, Chapter 14.1.1) has a little note on this topic: "auto-commit should always be turned off when batch updates are done. The commit behavior of executeBatch is always implementation-defined when an error occurs and auto-commit is true" I cannot find any clear definition whether the batch should be treated as a single transaction or multiple transactions depending on the state of autocommit. There is one hint though: Chapter 10.1 "The Connection attribute auto-commit specifies when to end transactions. Enabling auto-commit causes a transaction commit after each individual SQL statement as soon as that statement is complete. The point at which a statement is considered to be “complete” depends on the type of SQL statement as well as what the application does after executing it:" For Data Manipulation Language (DML) statements such as Insert, Update, Delete, and DDL statements, the statement is complete as soon as it has finished executing. .... For CallableStatement objects or for statements that return multiple results, the statement is complete when all of the associated result sets have been closed, and all update counts and output parameters have been retrieved. I think the second item (actually the third because I left out one) is interesting. A prepared statement that is using batches might be considered as one that returns multiple results (as it can return multiple update counts). So according to that note, I would actually say that batched statements _can_ be treated as a single transaction. Pretty vague though I have to admit. Regards Thomas