Return-Path: Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: (qmail 88388 invoked from network); 9 Jul 2009 20:06:13 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 9 Jul 2009 20:06:13 -0000 Received: (qmail 79664 invoked by uid 500); 9 Jul 2009 20:06:23 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 79630 invoked by uid 500); 9 Jul 2009 20:06: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 79622 invoked by uid 99); 9 Jul 2009 20:06:22 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Jul 2009 20:06:22 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of dmclean62@gmail.com designates 209.85.132.245 as permitted sender) Received: from [209.85.132.245] (HELO an-out-0708.google.com) (209.85.132.245) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Jul 2009 20:06:14 +0000 Received: by an-out-0708.google.com with SMTP id d40so173869and.40 for ; Thu, 09 Jul 2009 13:05:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=A7a/RoJnIiCHDfYmLD4emcX8AiAN1eG/jVJtyUTrabE=; b=yHy4yR5Dj04toeAuA92meshiDHK2KJtrGv0/960tVprzGsQ4pMl71yNrJALnlZJB6l gdN91pjg74WYVRtFJ7lqJEpECkkJrLRgBNDYVYRUzMwhfl4AjbEsw5c1xia6RzZD7z1S HOh8mDWJW+PkZtKlVo/s8Y11ciVDFTt0dsdoc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=ZVUpyTGF1oYSHaVU8UdyDkv64qPaOLrPoRn1ZRs4B9qEPUcgl4it8pCgl9IN0SVlvV ViXDaoN5HPp+tv5Mo91HAtLuSSrVz/kHbpYHIqCUaJHdPKWW23HLZ9EDLXzZkBhQ8XbN 4iYDOtcp11N3BSCydmRRqxZkaR/V+GW7WtpRk= MIME-Version: 1.0 Received: by 10.100.91.15 with SMTP id o15mr1647266anb.47.1247169953204; Thu, 09 Jul 2009 13:05:53 -0700 (PDT) In-Reply-To: <24415040.post@talk.nabble.com> References: <24415040.post@talk.nabble.com> Date: Thu, 9 Jul 2009 16:05:53 -0400 Message-ID: <5627810d0907091305m268d29a0k40690273dd9fc2fc@mail.gmail.com> Subject: Re: Problem with auto-generated identifiers From: Donald McLean To: Derby Discussion Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org It seems that you would get that if you created a second object before saving the first one. This could also happen if you had multiple threads or multiple users accessing a server DB. I would think that you would want to use "GENERATED ALWAYS AS IDENTITY" for event_id rather than generating the key through Hibernate. On Thu, Jul 9, 2009 at 2:12 PM, Dimka wrote: > > I am using embedded derby driver 10.4.2.0 - (689064) =A0with hibernate > Every once in a while I'm seeing an exception like this: > > "The statement was aborted because it would have caused a duplicate key > value in a unique or primary key constraint or unique index identified by > 'SQL090709201522730' defined on 'MYTABLE' " > > I haven't seen such problems up until I've started to use auto-generated > identifiers, like the one below: > > > =A0 =A0 =A0 =A0 > =A0 =A0 =A0 =A0 > > > Fraction of the schema looks like this: > CREATE TABLE MYTABLE(EVENT_ID BIGINT NOT NULL, .... PRIMARY KEY (EVENT_ID= )) > CREATE TABLE hibernate_unique_key ( next_hi INTEGER ) > INSERT INTO =A0hibernate_unique_key VALUES ( 0 ) > > The exception is thrown sometimes, not all the time.. I can't figure out = why > and when. > This is the most frustrating thing. > Can anyone give me a direction of where to look? ------------------------------------------------------------- Family photographs are a critical legacy for ourselves and our descendants. Protect that legacy with a digital backup and recovery plan.