RE: Help: SQL Server and AUTO_PK_SUPPORT/auto_pk_for_table

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Thu Oct 21 2004 - 12:55:48 EDT

  • Next message: Andrus Adamchik: "Re: Prefetching with inheritance oddity"

    Also I wanted to note that identity column support is #1 on the 1.2
    feature list... This or next weekend 1.1 release will be switched to
    STABLE CVS branch, and I will start the work on adding identity column
    support. So it should become available pretty soon as a part of 1.2
    milestone release.

    Andrus

    > I’ve ran into the same issue a while back, when we started developing
    > over Sql Server. Basically we had an integer primary key defined over a
    > table and this pk attribute was set to be an identity column for auto
    > incremented pk values (which sql server handled). If you try to insert a
    > value into this column sql server comes back with an error simply saying
    > that you can not by default insert into identity columns.
    >
    > Cayenne generates its own primary keys for objects to be inserted hence
    > an insert using standard Cayenne procedure would attempt to insert a
    > "cayenne generated pk value" into the identity column. Thus the problem,
    > well at least in our case.
    >
    > Without changing the tables as far as I know you can call “SET
    > IDENTITY_INSERT some_table ON" where some_table is the table name of the
    > table that contains this identity column that you are trying to insert a
    > value into. This call should be made before you insert statement.
    >
    > Our solution and I suppose because we had the freedom to change the
    > database was to dump identity columns in sql server all together and let
    > Cayenne manage the pks, it does it quite well.
    >
    > Hope this helps somewhat...
    >
    > - Gary
    >
    >
    > ________________________________________
    > From: Claudio Rosati [mailto:claudio.rosat..csys.it]
    > Sent: Thursday, October 21, 2004 5:43 PM
    > To: cayenne-use..bjectstyle.org
    > Subject: Help: SQL Server and AUTO_PK_SUPPORT/auto_pk_for_table
    >
    > Hello all,
    >
    > I'm working with an SQL Server DB. The tables I've reversed with Cayenne
    > Modeler have their PK that I think is auto-generated (auto-incremented:
    > DbVisualizer say me their type is "int identity").
    >
    > First time I've created a new mapped object i had a Cayenne exception
    > related to a lack of auto_pk_for_table procedure.
    >
    > Then, after diving the documentation, I've used the Modeler to create
    > AUTO_PK_SUPPORT table and the auto_pk_for_table procedure.
    >
    > Now the eception is the following (translated from italian):
    >
    > java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for
    > JDBC][SQLServer] Impoossible to insert an explicit value for the
    > Identity column of the 'trx_bundle' table when IDENTITY_INSERT is OFF.
    >
    > Why? What it means? How to solve it without change the tables?
    >
    > Thanks in advance
    >
    > Claudio
    >
    >
    >
    > Multimedia Division
    >
    >
    > Claudio Rosati
    > Project Manager
    > Advanced Computer Systems S.p.A.
    > via Della Bufalotta 378
    > 00139 Roma, RM
    > Italy
    > claudio.rosat..csys.it
    > tel:
    > fax:
    > +39 06 8709 0516
    > +39 06 8720 1502
    >
    >
    >
    >
    >
    > Add me to your address book...
    > Want a signature like this?
    >
    >



    This archive was generated by hypermail 2.0.0 : Thu Oct 21 2004 - 12:55:50 EDT