RE: column name twice error

From: Craig Miskell (cmiskel..lbatross.co.nz)
Date: Mon Apr 14 2003 - 21:05:58 EDT

  • Next message: martin ruff: "executing raw sql"

    In essence, the "unique" identifier enables an object that represents a
    given data row to be unique within a DataContext. So in some senses, it
    potentially identifies multiple objects in different DataContext's, but
    they all refer to the same data row. Kinda confusing at first, but it
    makes sense, to me at least :-)

    ObjectId overrides equals (and hashcode for contract reasons) to ensure
    that multiple instances with the same class and pk values will be
    "equal". Thus, you can take an ObjectId from an object in one
    DataContext and get a Hollow object in another context (or a non-hollow
    object, if the other context already knows about the object in question)
    e.g:

    DataObject
    objectInOtherContext=anotherContext.registeredObject(anObjectInFirstContext.getObjectId()).

    Similarly, if you manually construct an ObjectId and pass it to
    registeredObject(), then you'll get the unique object for that ObjectId
    in the target context.

    HTH

    Craig

    On Tue, 2003-04-15 at 12:11, Scott Finnerty wrote:
    > The ObjectId happens to be composed using the primary key (map of db
    > attribute, value pairs that comprise the key) - so yes it happens to be of
    > use across contexts... though whether this is by happy coincidence or by
    > design is a question. It seems it depends on how one interprets the
    > following from ObjectId's docs:
    >
    > "An ObjectId is a class that uniquely identifies a persistent object.
    > Each data object has an id uniquely identifying it. ..."
    >
    > If there is no alternate key on the data object that is exposed as an object
    > attribute, then some sort of work-around is necessary.
    >
    > Scott
    >
    > -----Original Message-----
    > From: John Poole [mailto:john..IXXURESCANADA.com]
    > Sent: Monday, April 14, 2003 4:59 PM
    > To: cayenne-use..bjectstyle.org
    > Subject: RE: column name twice error
    >
    >
    > I think I can work around the bug by changing the autogenerated setting
    > in mysql or something.
    > But as to how it should be done: Is the objectid going to be of
    > any use as a reference if I access the database with another
    > application? I'm using one machine and (therefore a separate vm) to
    > update the database and another to run a tomcat app. I'm also submitting
    > data to another website and getting confirmation on a different
    > connection. My plan is to use the primary key as the identifier for
    > which transaction is being confirmed.
    >
    > John
    >
    >
    >
    > -----Original Message-----
    > From: Scott Finnerty [mailto:scot..odefuey.com]
    > Sent: April 14, 2003 3:08 PM
    > To: cayenne-use..bjectstyle.org
    > Subject: Re: column name twice error
    >
    > I thought someone pointed the cause out on the list previously, but the
    > problem is with using a PK as an object attribute where the PK is also
    > auto-generated. The insert builder doesn't recognize the overlap
    > (obviously) and puts the column in twice - once for the auto-generated
    > PK
    > and once for the object attribute.
    >
    > The bit in the user guide about meaningful primary keys, etc. hints at
    > the issue - if you have a PK that you want to expose as an object
    > attribute, e.g., an SSN or the like - its likely not auto-generated and
    > specific to the DB. If it is auto-generated and specific to the DB then
    >
    > the philosophy is that it doesn't belong in the object model.
    >
    > I struggled with this, particularly in a web application context where
    > you
    > need a unique identifier for an object from request to request and not
    > all
    > database entities have alternate keys that can be used for this purpose.
    >
    > There have been messages on the list talking about using the ObjectId
    > instead of exposing the PK as an object attribute. This is pretty tight
    > coupling with an ObjectId and the docs warn against this. It works
    > though
    > and with minimal work you can isolate the tight coupling to a helper
    > class.
    >
    > Scott
    >
    > > John,
    > >
    > > Similar problem was reported here:
    > >
    > >
    > > http://sourceforge.net/tracker/
    > > index.php?func=detail&aid=709799&group_id=48132&atid=452068
    > >
    > > I could never reproduce this myself, but then insert statement
    > > generation has changed significantly since alpha 6. Does it also bomb
    > > when upgrading Cayenne to the latest nightly build?
    > >
    > > Andrus
    > >
    > > On Monday, April 7, 2003, at 11:00 AM, John Poole wrote:
    > >> v1.0a6
    > >> Cayenne is generating a statement which names the same column twice.
    > >> i.e. INSERT INTO aTable (id, userid, id) values (?, ?, ?)
    > params[null,
    > >> 100, null];
    > >>
    > >> I have a table in mySQL that has an auto-generated primary key
    > column,
    > >> which I need to use as a reference to another website. I've created
    > an
    > >> object attribute for the "id" column, this seems to adding a second
    > >> "id"
    > >> to the insert statement. I've done this before with other tables, and
    > >> I can't see anything in the datamap that looks "wrong".
    > >>
    > >> Is there a "better" way to get a unique key for a row?
    > >>
    > >> John
    >
    >
    >
    >
    >



    This archive was generated by hypermail 2.0.0 : Mon Apr 14 2003 - 21:10:41 EDT