Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id D171C200B54 for ; Thu, 28 Jul 2016 21:49:41 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id C578A160A85; Thu, 28 Jul 2016 19:49:41 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id E504F160A56 for ; Thu, 28 Jul 2016 21:49:40 +0200 (CEST) Received: (qmail 5986 invoked by uid 500); 28 Jul 2016 19:49:40 -0000 Mailing-List: contact user-help@cayenne.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@cayenne.apache.org Delivered-To: mailing list user@cayenne.apache.org Received: (qmail 5974 invoked by uid 99); 28 Jul 2016 19:49:39 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 28 Jul 2016 19:49:39 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 56FE9CED11 for ; Thu, 28 Jul 2016 19:49:39 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.179 X-Spam-Level: ** X-Spam-Status: No, score=2.179 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_REPLY=1, HTML_MESSAGE=2, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd1-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id N6bXWdom9y2x for ; Thu, 28 Jul 2016 19:49:37 +0000 (UTC) Received: from mail-qt0-f172.google.com (mail-qt0-f172.google.com [209.85.216.172]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id 727CE5F472 for ; Thu, 28 Jul 2016 19:49:36 +0000 (UTC) Received: by mail-qt0-f172.google.com with SMTP id x25so54824053qtx.2 for ; Thu, 28 Jul 2016 12:49:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=vecdSt2UfHd5CmWytjxbWrrYwMf6CtQwSyxdYKal8A4=; b=fvdE5U90LoK/HVF7wr5oN7IH1WA8CeV+eUYcevNAmik7C2SSqujXK3vVIoeB23Xn2J lZrcEI59PLMCynRY0n+vwvWs/htTKilKfAvjpkINBAzBjhIe6BGSJVKBQHKYUEXaPpPc n29ZAks2XJ1W6HBZGi1ZWJnctDM4swlGVAYU6uywbS4cUXxiV3sxr5w3t0vlhjl0Xjlq rRGxIDaFu1z7/Tu2mk3aTR2Lyy6wAh77KS/pyVYgXtavdgACF89r3Di+TOxQbpO7VbUA jasAY+3vOgzFlEDeOb5V5nGNytALVg+9KSuImKxvVT14vZTaX/KpbS7S/FQKWFotI0TI ZirA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=vecdSt2UfHd5CmWytjxbWrrYwMf6CtQwSyxdYKal8A4=; b=Uxco+tSPPuCqrIafVwYNWM+2tXGBsaKjV28D3ZQiFEkLb/8bGbpG45g5zvNdpDGOAl vob6CDUy+sqgp0oVCLGYrm8QjO5iCUc54GyokRQX1yXsD0eMa5H/NhWnmGyufqqBU093 X7rSiCZlD76xB8dW95iT6y1sBS4Qk2lKs7i6+SIjIGRqqKZ3YBzvjEZd8iX9v46RKzkq xutu9LVl6lsWg5NM2MOFl6U5icml41MET8e1syyMKcDEEDXc02MZQZgANuBdWgHo6QyK X70AIC655dX/zfZunfACkJXCfFyCz3aGinm7bZgmmlWu6y8xdm3O3Q3L3puzsyz6aFkW tesQ== X-Gm-Message-State: AEkooutctXHjK3OlwUTFamWhjLdDZ1LXVIhHa2htkw76eMFH+UXXHEQPhm1n3sF2OHiRhbNBw3kwTGg1hw0mIQ== X-Received: by 10.200.50.82 with SMTP id y18mr56955206qta.29.1469735375300; Thu, 28 Jul 2016 12:49:35 -0700 (PDT) MIME-Version: 1.0 References: <2748AFD8-D20C-40DF-A1E3-3D71FEEF9824@objectstyle.org> <6CFA2CC8-9670-4982-90D9-9DDAEBF0CB78@objectstyle.org> In-Reply-To: From: John Huss Date: Thu, 28 Jul 2016 19:49:25 +0000 Message-ID: Subject: Re: auto PK generation in Cayenne 4 + PostgreSQL combination? To: user@cayenne.apache.org Content-Type: multipart/alternative; boundary=001a113ff53cf57d770538b76edf archived-at: Thu, 28 Jul 2016 19:49:42 -0000 --001a113ff53cf57d770538b76edf Content-Type: text/plain; charset=UTF-8 Cayenne generates them like this: CREATE SEQUENCE mytable_seq INCREMENT 20 START 200; The start part is optional. On Thu, Jul 28, 2016 at 2:02 PM Harunobu Oyama wrote: > Sorry, how should I create the sequence? If Cayenne increments the value in > blocks f 20? > > nobu > > > On 28 July 2016 at 19:58, John Huss wrote: > > > By default cayenne expects the sequence to be incremented in blocks of > 20, > > not by 1, so you have to specify that when you create the sequence. > Using > > serial columns is very very small improvement and since support is still > a > > ways off you would be much better off just creating your sequences and > > letting cayenne use them. > > > > > > On Thu, Jul 28, 2016 at 1:53 PM Harunobu Oyama wrote: > > > > > It seems "last_value" of "pk_asset" is not updated as expected. > > > It gets incremented only once even if I create 3 asset records using > > > Cayenne. > > > It ends up violating asset_PKC constraint. > > > > > > > > > The SQL is like following. > > > > > > create table "asset" ( > > > "asset_id" bigserial not null > > > , "name" character varying not null > > > , "latitude" double precision > > > , "longitude" double precision > > > , constraint "asset_PKC" primary key ("asset_id") > > > ) ; > > > > > > create sequence "pk_asset" > > > > > > I think it is better to change bigserial to bigint, but does it matter? > > > > > > > > > nobu > > > > > > > > > > > > > > > On 28 July 2016 at 16:15, Michael Gentry wrote: > > > > > > > What do you mean by "out of sync"? Does it generate duplicate PKs? > > How > > > > did you create your sequence? (Can you show us the SQL for it?) > > > > > > > > Thanks, > > > > > > > > mrg > > > > > > > > > > > > > > > > On Thu, Jul 28, 2016 at 11:10 AM, Harunobu Oyama > > wrote: > > > > > > > > > If I do not create "pk_asset" sequence, Cayenne 4 throws an > Exception > > > > > saying it requires it. > > > > > If I create "pk_asset" and let Cayenne 4 assigns the PK using > > > "pk_asset", > > > > > it looks working fine at a glance, but pk_asset's last_value gets > > out > > > of > > > > > sync, the next time we launch the program. > > > > > nobu > > > > > > > > > > On 28 July 2016 at 16:05, Michael Gentry > > wrote: > > > > > > > > > > > Well, you can still use PostgreSQL's sequences. After all, > that's > > > what > > > > > the > > > > > > "serial" type inherently uses. No need to manually set the PKs. > > > > > > > > > > > > mrg > > > > > > > > > > > > > > > > > > On Thu, Jul 28, 2016 at 10:15 AM, Harunobu Oyama > > > > > wrote: > > > > > > > > > > > > > Thank you Andrus and Michael, > > > > > > > > > > > > > > I will workaround the issue, probably by explicitly setting the > > > PK's > > > > > from > > > > > > > Java code, until it gets officially supported by Cayenne then. > > > > > > > > > > > > > > nbou > > > > > > > > > > > > > > > > > > > > > > > > > > > > On 28 July 2016 at 15:11, Andrus Adamchik < > > andrus@objectstyle.org> > > > > > > wrote: > > > > > > > > > > > > > > > Good to know this is finally supported on PG :) > > > > > > > > > > > > > > > > And yeah, we'll still need to patch Cayenne, so we'll also > > > address > > > > PG > > > > > > > > driver specifics. > > > > > > > > > > > > > > > > Andrus > > > > > > > > > > > > > > > > > On Jul 28, 2016, at 5:01 PM, Michael Gentry < > > > blacknext@gmail.com > > > > > > > > > > > > wrote: > > > > > > > > > > > > > > > > > > A little Google searching found: > > > > > > > > > > > > > > > > > > https://github.com/pgjdbc/pgjdbc/issues/99 > > > > > > > > > > > > > > > > > > This leads me to believe > BatchAction.runAsIndividualQueries() > > > > would > > > > > > > have > > > > > > > > to > > > > > > > > > be changed for PostgreSQL, otherwise all of the column > values > > > are > > > > > > > > returned > > > > > > > > > instead of just the new PK value. > > > > > > > > > > > > > > > > > > mrg > > > > > > > > > > > > > > > > > > > > > > > > > > > On Thu, Jul 28, 2016 at 9:45 AM, Michael Gentry < > > > > > blacknext@gmail.com > > > > > > > > > > > > > > > wrote: > > > > > > > > > > > > > > > > > >> The PostgreSQL documentation says: > > > > > > > > >> > > > > > > > > >> CREATE TABLE tablename ( > > > > > > > > >> colname SERIAL > > > > > > > > >> ); > > > > > > > > >> > > > > > > > > >> is equivalent to specifying: > > > > > > > > >> > > > > > > > > >> CREATE SEQUENCE tablename_colname_seq; > > > > > > > > >> CREATE TABLE tablename ( > > > > > > > > >> colname integer NOT NULL DEFAULT > > > > > nextval('tablename_colname_seq') > > > > > > > > >> ); > > > > > > > > >> ALTER SEQUENCE tablename_colname_seq OWNED BY > > > tablename.colname; > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> We'd have to see if the JDBC driver returns the sequence > > value > > > > > > > generated > > > > > > > > >> for the serial column. > > > > > > > > >> > > > > > > > > >> mrg > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> On Thu, Jul 28, 2016 at 9:10 AM, Andrus Adamchik < > > > > > > > > andrus@objectstyle.org> > > > > > > > > >> wrote: > > > > > > > > >> > > > > > > > > >>> Back in the day PG driver did not support autoincremented > > > > values > > > > > at > > > > > > > the > > > > > > > > >>> JDBC level. So we had to always revert to sequences. > > > > > > > > >>> > > > > > > > > >>> I'd like to run a test to see if it does now. If the test > > is > > > > > > > > successful, > > > > > > > > >>> we can reconfigure Cayenne PostgresAdapter to enable > > > > > aoto-increment > > > > > > > > >>> strategy. Will keep the list posted. > > > > > > > > >>> > > > > > > > > >>> Andrus > > > > > > > > >>> > > > > > > > > >>> > > > > > > > > >>>> On Jul 28, 2016, at 12:48 PM, Harunobu Oyama < > > > ho@telensa.com> > > > > > > > wrote: > > > > > > > > >>>> > > > > > > > > >>>> Hi, > > > > > > > > >>>> > > > > > > > > >>>> > > > > > > > > >>>> What is the proper way to setup auto PK generation when > > > > Cayenne > > > > > 4 > > > > > > + > > > > > > > > >>>> PostgreSQL are in use? > > > > > > > > >>>> > > > > > > > > >>>> Suppose I have a simple table like this. > > > > > > > > >>>> > > > > > > > > >>>> create table "asset" ( > > > > > > > > >>>> "asset_id" bigserial not null > > > > > > > > >>>> , "name" character varying not null > > > > > > > > >>>> , constraint "asset_PKC" primary key ("asset_id") > > > > > > > > >>>> ) ; > > > > > > > > >>>> > > > > > > > > >>>> No matter how I configure the PK generation settings, it > > > seems > > > > > > > Cayenne > > > > > > > > >>>> runtime > > > > > > > > >>>> requires sequence named "pk_asset". > > > > > > > > >>>> > > > > > > > > >>>> Ideally we would like to automate the table-sequence > > > > combination > > > > > > by > > > > > > > > >>> using > > > > > > > > >>>> serial/bigserial. > > > > > > > > >>>> > > > > > > > > >>>> How can I tell Cayenne stop requiring "pk_asset"? > > > > > > > > >>>> > > > > > > > > >>>> > > > > > > > > >>>> thank you, > > > > > > > > >>>> nobu > > > > > > > > >>> > > > > > > > > >>> > > > > > > > > >> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > --001a113ff53cf57d770538b76edf--