Re: Understanding Pks:

From: Laszlo Spoor (lspoor_cayenn..otmail.com)
Date: Thu Jul 24 2003 - 17:05:03 EDT

  • Next message: Fabricio Voznika: "Object validation"

    Hi Adrian,

    I would like to respond to your question as well. I have been using both
    Cayenne and TopLink as persistance layers for different websites. My opinion
    (at least for websites) is, that you should _always_ incorporate a technical
    primary key on both the object- and database level.

    The reason is that when you incorporate a technical id for each
    object/entity, you are able to find information in a consistent way. If, for
    example, you have a composite pk (lets say: a_id, b_id, date_date), then you
    have to go through the hassle of writing a query for this case, while if
    you'd just incorporated a technical key, it is much easier to retrieve data,
    cause you do it always like that in the other situations.

    My tip for the object model is: create a superclass let's say:
    MyApplicationObject, which contains a unique identifier and subclass all
    other objects from there. As for the datamodel, if possible, always create a
    primary key id for each entity.

    It might not be the the most purest way in the sense of object modelling and
    database modelling, but I find it certainly the most pleasant way to work
    with. In my opinion it will save you a lot of time and delivers more
    consistent and easier to maintain code.

    I would like to make a small note about intersection tables (in Cayenne
    terms flattened relationships; tables that are created to achieve n:m
    relationships) that this 'could' be an exception. If there is not extra
    information needed to store relationships, there is no need to create a Java
    Object for this relationship and use the flattened relationships concept of
    Cayenne to map it.

    But if you do need to map extra info, like a date, a type or whatever, save
    yourself some headaches: incorporate a technical key,l create an Object for
    it and threat the relationship as you would any other object.

    Hope this helps, Laszlo

    >From: Adrian <kadrianu..ahoo.com>
    >To: cayenne-use..bjectstyle.org
    >Subject: Understanding Pks:
    >Date: Tue, 22 Jul 2003 20:27:30 -0700 (PDT)
    >
    >This is a basic question but I don know how to handle it:
    >
    >I.e. ...if a I have a table STATES, that table has two fields: ID_STATE and
    >NAME...
    >ID_STATE is the PK field and it is autogenerated using cayenne pk
    >generation support.
    >
    >The modeler generates a class with only the name attribute (pk fields
    >doesn't get reflected on class generation)....My question is: if i.e. I
    >want to populate a combo with all the values of this table and I want to
    >label the option with the field NAMEbut set the option's real value with
    >ID_STATE field value...how can I get this value from the class if I the
    >modeler doesn't create a proper attribute and its getter/setter
    >methods...surely I'am missing something...any help will be
    >appreciated...Thx in advance!
    >
    >
    >---------------------------------
    >Do you Yahoo!?
    >Yahoo! SiteBuilder - Free, easy-to-use web site design software

    _________________________________________________________________
    Add photos to your e-mail with MSN 8. Get 2 months FREE*.
    http://join.msn.com/?page=features/featuredemail



    This archive was generated by hypermail 2.0.0 : Thu Jul 24 2003 - 17:02:32 EDT