Re: Why must generate AUTO_PK_SUPPORT table ?

From: Andrus (andru..bjectstyle.org)
Date: Thu Nov 14 2002 - 21:15:13 EST

  • Next message: Dirk Olmes: "Re: sort attribute for referenced relation"

    Hi yadan,

    You've encountered an automatic primary key generation feature in Cayenne.
    Read more about it here:

    http://objectstyle.org/cayenne/userguide/design/autopk.html

    Are you familiar with the primary key concept? If yes, then my explanation
    is redundant, but anyway.

    Basically, no matter how you save your data, (even if you don't use Cayenne
    at all, but use JDBC instead), you need a way to assign a *unique* id to
    each newly created record in the database. In some cases this id is known
    to the Java application and is part of the business logic (for instance
    such id may be an account number). But in most cases it is a pure database
    concept - a sequential number automatically generated on each insert.

    AUTO_PK_SUPPORT table, though being a Cayenne artifact, is using a common
    approach to store id's so that no matter what application writes to the
    database, it knows how to assign id's to the new rows. Think of it as a
    helper table that is not related to your application logic, but rather it
    is a technicality that helps to maintain unique row ids.

    Andrus

    At 02:27 PM 11/14/2002 +0800, yadan wrote:
    >As a normal database ,there is no a schema like "AUTO_PK_SUPPORT". But
    >when I use cayenne writing code, it's likely that I must create the schema
    >using the CayenneModelor menu.
    >The sql generated are below:
    >"
    >CREATE TABLE AUTO_PK_SUPPORT ( TABLE_NAME CHAR(100) NOT NULL, NEXT_ID
    >INTEGER NOT NULL)
    >
    >DELETE FROM AUTO_PK_SUPPORT WHERE TABLE_NAME IN ('artist', 'gallery',
    >'painting')
    >
    >INSERT INTO AUTO_PK_SUPPORT (TABLE_NAME, NEXT_ID) VALUES ('artist', 200)
    >
    >INSERT INTO AUTO_PK_SUPPORT (TABLE_NAME, NEXT_ID) VALUES ('gallery', 200)
    >
    >INSERT INTO AUTO_PK_SUPPORT (TABLE_NAME, NEXT_ID) VALUES ('painting', 200)
    > "
    >I don't know why . If I haven't generate the "AUTO_PK_SUPPORT"
    >schema,exceptions are thrown:
    >"java.sql.SQLException: General error: Table 'cayenne.auto_pk_support'
    >doesn't exist"
    >(My code is only insert a record to Artist)
    >
    >If I want work with cayenne and my database schema should not changed(no
    >extra schemas add), how should I do it ?



    This archive was generated by hypermail 2.0.0 : Thu Nov 14 2002 - 21:14:58 EST