Re: Help with PK field accessible by web app

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Mon May 26 2003 - 21:17:15 EDT

  • Next message: Andrus Adamchik: "Re: Help with PK field accessible by web app"

    > I would love to have some type of ObjectId that I could print to string
    > and then from a string do a
    >
    > Category = ctxt.loadObjectById(Category.class, objectIdString);
    >
    > Are there any hints how to achieve what I want without losing the
    > autogenerate PK? I would be willing to add another column, but I did
    > not want to worry about generating values for this myself. I like the
    > abstraction of just worrying about the objects and not the underlying db
    > with this one exception.
    >
    > Maybe I should change the way I think about writing this type of
    > Add/Edit/Delete stuff for Cayenne.

    I was lucky to have most of my web development experience acquired using
    WebObjects, where there is no need to think of such things, but well...
    the rest of the world have to handle this manually :-). Cayenne wouldn't
    change this much, it is a presentation layer to blame.

    Anyway, answering your question, given an integer, you can easily obtain
    an object in Cayenne, , and vice versa, exposing only a little bit of the
    underlying database :

      // getting id from object
      Object id =
          categoryObject.getObjectId().getValueForAttribute("CATEGORY_ID");

      // getting object for id
      int id = Integer.parseInt(idString);
      ObjectId objectId = new ObjectId(Category.class, id);
      Category category = (Category)ctxt.registeredObject(objectId);

    I guess we need to put this somewhere in the User Guide, looks like doing
    this is unavoidable sometimes...

    Hope this helps.

    Andrus



    This archive was generated by hypermail 2.0.0 : Mon May 26 2003 - 21:17:15 EDT