Re: Postgress autogenerated keys.

From: Reid Thompson (reid.thompso..teb.com)
Date: Thu Oct 29 2009 - 00:03:25 EDT

  • Next message: lenka: "PasswordSource if passwordLocation is executable"

    Emanuele Maiarelli wrote:
    > I'm using cayenne 3 with postgresql 8.2.14, for instance i've a table
    > structured like that
    >
    > CREATE TABLE documenti
    > (
    > doc_pk bigserial NOT NULL,
    > doc_desc character varying(255),
    > doc_mine character varying(255),
    > doc_prot_fk bigint,
    > doc_self_fk bigint,
    > doc_prot_nr bigint,
    > doc_folder_fk bigint,
    > doc_uid character varying(255),
    > doc_prot_anno bigint,
    > doc_unsubmitted boolean,
    > CONSTRAINT "DOCUMENTI_pkey" PRIMARY KEY (doc_pk),
    > CONSTRAINT "DOCUMENTI_DOC_PROT_FK_fkey" FOREIGN KEY (doc_prot_fk)
    > REFERENCES protocolli (prot_pk) MATCH SIMPLE
    > ON UPDATE NO ACTION ON DELETE NO ACTION,
    > CONSTRAINT documenti_doc_folder_fk_fkey FOREIGN KEY (doc_folder_fk)
    > REFERENCES folders (fold_pk) MATCH SIMPLE
    > ON UPDATE NO ACTION ON DELETE NO ACTION
    > )
    > WITHOUT OIDS;
    > and a sequnce for generating Pks
    >
    > CREATE SEQUENCE documenti_doc_pk_seq
    > INCREMENT 1
    > MINVALUE 1
    > MAXVALUE 9223372036854775807
    > START 20
    > CACHE 1;
    >
    > My question is what's the best pratice to ensure correts Pks being
    > generated from sequence:
    >
    > actually entity is configured as follow
    >
    > <db-entity name="documenti" schema="public">
    > <db-attribute name="doc_desc" type="VARCHAR" length="255"/>
    > <db-attribute name="doc_folder_fk" type="BIGINT" length="8"/>
    > <db-attribute name="doc_mine" type="VARCHAR" length="255"/>
    > <db-attribute name="doc_pk" type="BIGINT" isPrimaryKey="true"
    > isMandatory="true" length="8"/>
    > <db-attribute name="doc_prot_anno" type="BIGINT" length="8"/>
    > <db-attribute name="doc_prot_fk" type="BIGINT" length="8"/>
    > <db-attribute name="doc_prot_nr" type="BIGINT" length="8"/>
    > <db-attribute name="doc_self_fk" type="BIGINT" length="8"/>
    > <db-attribute name="doc_uid" type="VARCHAR" length="255"/>
    > <db-attribute name="doc_unsubmitted" type="BIT" length="1"/>
    > <db-key-generator>
    > <db-generator-type>ORACLE</db-generator-type>
    > <db-generator-name>documenti_doc_pk_seq</db-generator-name>
    > <db-key-cache-size>1</db-key-cache-size>
    > </db-key-generator>
    > </db-entity>
    >
    > but since i missed initially to specify
    > <db-key-cache-size>1</db-key-cache-size> i got duplicated keys problems.
    >
    > Specifing <db-key-cache-size>1</db-key-cache-size> seems like solve the
    > problem. Is this correct?
    >
    >
    > Or should i change postgresql to automatically create the pk i mean,
    > changing doc_pk like that "doc_pk bigserial NOT NULL DEFAULT
    > nextval('documenti_doc_pk_seq')
    >
    > and setting
    > <db-attribute name="doc_pk" type="BIGINT" isPrimaryKey="true"
    > isGenerated="true" isMandatory="true" length="8"/>
    >
    >
    >
    >
    >
    >

    let the db manage it, that's what it's designed for



    This archive was generated by hypermail 2.0.0 : Thu Oct 29 2009 - 00:03:54 EDT