Re: UUID as primary key

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Wed Jul 12 2006 - 10:36:18 EDT

  • Next message: Gentry, Michael \(Contractor\): "RE: UUID as primary key"

    Yes, there are a few ways of doing this. The cleanest one is this:

    object.getObjectId().getReplacementIdMap().put(Treatment.BLA_BLA_PK,
    UUID.randomUUID());

    BTW, this code can be added to "setPersistenceState()" to be executed
    when persistence state is changed to NEW.

    Andrus

    On Jul 10, 2006, at 4:00 PM, Øyvind Harboe wrote:

    > Is there a way to set the primary key without mapping the primary key
    > as an object attribute?
    >
    > Or is there a more elegant way of handling UUID as pk?
    >
    > I have lots of tables where the pk is an UUID and the only reason why
    > I have to map the primary key as an object attribute is to be able to
    > set the pk to an UUID.
    >
    > // Create object
    > Treatment treatment = (Treatment)
    > dataContext.createAndRegisterNewObject(Treatment.class);
    > // set pk as UUID
    > treatment.setId(UUID.randomUUID());
    >
    > Where "setId()" is the primary key mapped as an ObjAttribute.
    >
    >
    >
    > --
    > Øyvind Harboe
    > http://www.zylin.com
    >



    This archive was generated by hypermail 2.0.0 : Wed Jul 12 2006 - 10:37:15 EDT