RE: Specifying PK when creating a new object in DB generated PK mode

From: Scott Anderson (sanderso..irvana.com)
Date: Tue May 06 2008 - 10:33:20 EDT

  • Next message: Julien Trolliet: "Commit with validation errors in detail table"

    Works great; thanks Andrus.

    -----Original Message-----
    From: Andrus Adamchik [mailto:andru..bjectstyle.org]
    Sent: Tuesday, May 06, 2008 4:30 AM
    To: use..ayenne.apache.org
    Subject: Re: Specifying PK when creating a new object in DB generated PK
    mode

    How about using a brute force approach. You have a DataMap that
    contains DbEntities with "Database Generated" PK. Fine... but for
    import purposes you need to suppress this behavior, so do something
    like that on startup:

    DataDomain domain = Configuration.getSharedConfiguration().getDomain();
    for(DbEntity e : domain.getEntityResolver().getDbEntities()) {
        for(DbAttribute a : e.getPrimaryKeys()) {
           a.setGenerated(false);
        }
    }

    Andrus



    This archive was generated by hypermail 2.0.0 : Tue May 06 2008 - 10:34:19 EDT