Re: Database Generated Ids

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Wed Oct 04 2006 - 10:47:47 EDT

  • Next message: DOMINGUEZ Felipe: "RE: Database Generated Ids"

    Hi Felipe,

    Here is a docs page on auto-incremented keys:

    http://cwiki.apache.org/confluence/display/CAYDOC/Generated+Columns

    Also see my comments below...

    On Oct 4, 2006, at 3:13 AM, DOMINGUEZ Felipe wrote:
    > Hello every body.
    >
    >
    > I am using Cayenne to query hsqldb.
    >
    > On HSQLDB I have a few tables with an auto-increment primary key.
    > When
    > I manually enter data onto those tables the key generation works fine.
    >
    > On the other hand cayenne always uses its own key generation,
    > generating
    > PK with the support of table AUTO_PK_SUPPORT.
    >
    > I did some research last night and I found out that I must set the
    > database custom adapter in the DomainNode adapter panel, so I set
    > it to
    > org.objectstyle.cayenne.dba.hsqldb.HSQLDBAdapter

    No, in 1.2 and newer this is optional. But you still want to do that
    if you are to follow the advice below.

    > But still, Cayenne uses AUTO_PK_SUPPORT

    True, there are two things involved in making auto-increment work.
    First you must select "Database-Generated" for "PK Generation
    Strategy" for each table in question. Second - Cayenne DbAdapter must
    support it. HSQLDB adapter thinks that it doesn't (although in fact
    it does), so you'll need to manually flip Auto PK flag:

    DataNode node = ...
    JdbcAdapter adapter = (JdbcAdapter) node.getAdapter();
    adapter.setSupportsGeneratedKeys(true);

    (I'll log an issue in Jira to make sure Cayenne does the right thing
    in the future).

    Andrus



    This archive was generated by hypermail 2.0.0 : Wed Oct 04 2006 - 10:49:48 EDT