Re: Type for class designator column when using STI?

From: Michael Gentry (blacknex..mail.com)
Date: Mon May 29 2006 - 10:37:55 EDT

  • Next message: Øyvind Harboe: "orExp resulting in *fewer* results"

    You should be able to use integers or strings (or others, but those
    are the most practical).

    When mapping to a legacy schema we have, I mapped PSEnumeratedItem as
    a subclass of PSItem. Set the Java class (I think the superclass is
    automatically set when you use the pulldown to specify the parent) to
    your desired class, and in the qualifier enter you criteria. For
    example, mine is:

    moniker = "ES"

    But you could easily have an integer listed in there. Cayenne should
    automatically create the correct class instance for you when it reads
    from the DB.

    Also, make sure you initialize the correct values when you create new
    objects (Cayenne doesn't do this for you automatically). For example:

    public class PSEnumeratedItem extends _PSEnumeratedItem
    {
      public void setPersistenceState(int state)
      {
        super.setPersistenceState(state);

        // if object was just created, initialize values
        if (state == PersistenceState.NEW)
        {
           setMoniker("ES");
        }
      }
    }

    /dev/mrg

    PS. My qualifier (they have to differ) for PSItem is: moniker = "QQ"
    PPS. I don't remember if it is required that the parent has a qualifier.

    On 5/26/06, Jeff de Vries <jdevrie..frog.com> wrote:
    > Does it matter what data type the "class designator column" is when
    > using STI? Are there any expectations on the values in the class
    > designator column? For example, can you use an integer column, with 1
    > meaning Employee, 2 meaning Manager, 3 meaning Customer, etc? Does
    > Cayenne know what class to instantiate by looking at the qualifier
    > expression?
    >
    > Thanks,
    > Jeff de Vries
    >
    >



    This archive was generated by hypermail 2.0.0 : Mon May 29 2006 - 10:38:19 EDT