Re: Empty Constructor

From: Michael Gentry (Yes, I'm a Contractor) ("Michael)
Date: Thu Jun 30 2005 - 15:12:08 EDT

  • Next message: Michael Gentry (Yes, I'm a Contractor): "Re: Subclassing a DataObject"

    Are you trying to set initial defaults or do you want to allow arbitrary
    values to be set on creation? If you just want to setup initial defaults
    (for newly created objects), do something like this in your entity subclass:

      public void setPersistenceState(int state)
      {
        super.setPersistenceState(state);
        
        // if object was just created, initialize values
        if (state == PersistenceState.NEW)
        {
           setFooBar("FOOBAR");
        }
      }

    > From: Kevin Menard <kmenar..ervprise.com>
    > Reply-To: <cayenne-use..bjectstyle.org>
    > Date: Thu, 30 Jun 2005 14:56:32 -0400
    > To: <cayenne-use..bjectstyle.org>
    > Subject: Empty Constructor
    >
    > If you haven't guessed by now, I'm trying to integrate Cayenne into a
    > new project here, thus all the questions ;-)
    >
    > I have a DataObject with some fields that I would like to be not
    > null. Typically, for such things, I'd force them to be passed into
    > the constructor to strengthen this commitment. So, I naively set
    > about doing that with my DataObject. Alas, it appears an accessible
    > empty constructor is necessary for retrieving things from the DB. Is
    > this in fact the case? I'd rather not have people instantiating the
    > no-arg constructor . . .
    >
    > --
    > Kevin



    This archive was generated by hypermail 2.0.0 : Thu Jun 30 2005 - 15:12:11 EDT