Re: Primary key generation issue

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Thu May 13 2004 - 16:38:05 EDT

  • Next message: Claudio Rosati: "R: R: event handling"

    > Is there a reason why you guys do no want to expose that possibility
    > as a flag? I am thinking of a simple AlsoGenerateKeyField textbox
    > kindda thing.

    No reason, it is just not there :-). Seriously, as one of the authors
    of the tool I didn't care about having a PK as an object property, so
    it wasn't implemented. However I recognize that many folks like to have
    it the other way, so I do not object to implement this option in the
    modeler. Besides, like you said, there are cases of meaningful PKs...

    So please submit a feature request at
    http://objectstyle.org/cayenne/bugs-features.html

    > String expKey = "101";
    >                 Expression qual3 =
    > ExpressionFactory.matchExp("depId",expKey);
    >                 SelectQuery query3 = new
    > SelectQuery(Department.class,qual3);
    >                 List deps3 = ctxt.performQuery(query3);

    You can use a little hack with DB expressions in this case. I can't say
    what breaks object abstraction more, using a DB column name in the
    code, or mapping an arbitrary id as an object property, but I digress
    :-) The example assumes that PK column name is "DEP_ID":

        Expression qual3 = Expression.fromString("db:DEP_ID = 101");

    Hope this helps.

    Andrus

    On May 13, 2004, at 3:37 PM, Mehdi Bennani wrote:

    > Hey Guys,
    >
    > I have a question: ( I am running 1.1)
    > Is there a way (without having to modify the cayenne code myself) to
    > tell the 'reengineer database schema' tool to also generate the keys
    > for the objEntities. I understand from the user guide documentation
    > that you can ake that, i.e: add  that PK manually, link it to the
    > dbentity field and then re-generate the classes, but I was wondering
    > whether there was a way for me to avoid doing that for every
    > entity..as it gets painful.....
    >
    > The reason is not only to be able to create new objEntities by setting
    > the Id (in case where the ids are meaningful. I.e: SSN, userLoginId
    > and so on...), but also for querying, and that is what bothers me the
    > most...I would like to be able to say:
    >
    >                 String expKey = "101";
    >                 Expression qual3 =
    > ExpressionFactory.matchExp("depId",expKey);
    >                 SelectQuery query3 = new
    > SelectQuery(Department.class,qual3);
    >                 List deps3 = ctxt.performQuery(query3);
    >                 ...
    > If the depId field is not present in the object model (i.e: the
    > Department objEntity), there is now way for me to be able to perform
    > such query. (unless maybe using parametrized query I believe...I am
    > not even sure.....or so...but that defies the purpose of the object
    > model abstraction).
    >
    > Thank you.
    > Sincerely,
    >
    > Mehdi Bennani
    > Software Engineer
    > FreeBalance Inc.
    > Visit the new FreeBalance website..www.FreeBalance.com
    >
    > T (613) 236-5150 ext.325
    > F (613) 236-7785
    > mbennan..reeBalance.com



    This archive was generated by hypermail 2.0.0 : Thu May 13 2004 - 16:38:12 EDT