cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Gentry" <blackn...@gmail.com>
Subject Re: Type for class designator column when using STI?
Date Mon, 29 May 2006 14:37:55 GMT
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 <jdevries@pfrog.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
>
>

Mime
View raw message