Return-Path: X-Original-To: apmail-db-derby-user-archive@www.apache.org Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id AF5BAD14B for ; Sat, 10 Nov 2012 15:52:29 +0000 (UTC) Received: (qmail 72111 invoked by uid 500); 10 Nov 2012 15:52:28 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 71575 invoked by uid 500); 10 Nov 2012 15:52:22 -0000 Mailing-List: contact derby-user-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Reply-To: "Derby Discussion" Delivered-To: mailing list derby-user@db.apache.org Received: (qmail 71519 invoked by uid 99); 10 Nov 2012 15:52:20 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 10 Nov 2012 15:52:20 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of bpendleton.derby@gmail.com designates 209.85.210.172 as permitted sender) Received: from [209.85.210.172] (HELO mail-ia0-f172.google.com) (209.85.210.172) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 10 Nov 2012 15:52:12 +0000 Received: by mail-ia0-f172.google.com with SMTP id x24so3834660iak.31 for ; Sat, 10 Nov 2012 07:51:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=8ZMXcOPGjp7/eqBXxw7yoxuPxrsevTiD5iS6eUDEQ10=; b=aQVMJeekkW2X+MqnlreH/xh0McVzWnExP92RZRTyBVUwoo5he8mgRlFPLPn+WhDRsj CRcsvCCzwJZSFgo/jZOTxyuMRtlOsA7hUJnDmT+4YzdIohk1+OiXxjMUZhRqeNoyfNFP LkOlN4Bxkz06tLZHyqyNTYblalb47aZ4Q1aBHlP6hMJ2MMmWpgKpCqkyFQFiTMjdRtOa nNvFCRVo3w7DP/amkvJK83Rc7y7u+lhI2tCa4C0y1PiRlhFZYT8xPOoLWtn6ggCV0pg3 JK2dKzMTrj5lCWoyb/tMOFUMfSZLEKRLzo3PqrP9zXRUBupxW0Mc38dZeCuypKcebmEF +Ufg== MIME-Version: 1.0 Received: by 10.50.159.198 with SMTP id xe6mr3645804igb.46.1352562711687; Sat, 10 Nov 2012 07:51:51 -0800 (PST) Received: by 10.231.58.16 with HTTP; Sat, 10 Nov 2012 07:51:51 -0800 (PST) In-Reply-To: References: Date: Sat, 10 Nov 2012 07:51:51 -0800 Message-ID: Subject: Re: derby (dead)lock exception From: Bryan Pendleton To: Derby Discussion Content-Type: text/plain; charset=ISO-8859-1 X-Virus-Checked: Checked by ClamAV on apache.org > . What does U and X mean after the trans. Ids? > > The query is: > > DELETE FROM TRIP_TIMETABLE > WHERE EXISTS( > SELECT ID FROM TRIP WHERE (ID IN (?)) AND ID = TRIP_TIMETABLE.trips_ID > ) > > What can be wrong with this query? I'm not exactly sure what's wrong, but I agree that they both appear to have gone after the same set of rows, but in different orders. I think that the '1,19' and '1,20' are row identifiers; the 19th row in table 1 and the 20th row in table 1, or something like that. Apparently there were two timetables for a certain trip, and one transaction was trying to delete timetable 19, then timetable 20, while the other was trying to delete timetable 20, then timetable 19. U and X are lock modes. U means: "I'm reading this row and intend to update it", while X means: "I'm updating this row." "Updating" can be any of: insert, update, delete; in your case it is delete. One way that I've used to get around problems like this in the past is a bit of a sledgehammer: immediately prior to the DELETE statement, but within the same transaction, you can do: LOCK TABLE TRIP IN EXCLUSIVE MODE LOCK TABLE TRIP_TIMETABLE IN EXCLUSIVE MODE. This technique works best if you adjust your code so that these three statements (the 2 LOCK TABLE statements, and the DELETE statement) are the only three statements in the transaction; that is, commit immediately before and immediately after this. Hope this gives you some clues. bryan