Return-Path: X-Original-To: apmail-cayenne-user-archive@www.apache.org Delivered-To: apmail-cayenne-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 829E8D3E4 for ; Fri, 27 Jul 2012 15:16:00 +0000 (UTC) Received: (qmail 78504 invoked by uid 500); 27 Jul 2012 15:16:00 -0000 Delivered-To: apmail-cayenne-user-archive@cayenne.apache.org Received: (qmail 78484 invoked by uid 500); 27 Jul 2012 15:16:00 -0000 Mailing-List: contact user-help@cayenne.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@cayenne.apache.org Delivered-To: mailing list user@cayenne.apache.org Received: (qmail 78475 invoked by uid 99); 27 Jul 2012 15:16:00 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Jul 2012 15:16:00 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=FSL_RCVD_USER,RCVD_IN_DNSWL_LOW,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [209.85.161.171] (HELO mail-gg0-f171.google.com) (209.85.161.171) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Jul 2012 15:15:55 +0000 Received: by ggmi1 with SMTP id i1so6067059ggm.16 for ; Fri, 27 Jul 2012 08:15:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:x-gm-message-state; bh=Hq16NDGi91uPueacL/xVsf0+C9R7tP5xlabyuBS95ks=; b=HRFUu/IveBwfXBZbyU7zQfETdgJMykiIeH16EbeLJ+aoSfYX5qndeNdw27PELDsiIB z0meaBBoHru+2jVTDfFKjiQGEcZyF9Ruzf/KkTHTnwsaaIou+R8pB95PHISGytXoNQUQ 8Y9rvBUBAL6tovW0PgkDHh8emXNXD48JrWzOrarK1e/mjzX40ANZX6wqWb2sGNBNOSiG Bm0fBaEzcfYxhjO+8ToH5XH3vV4AgpbzsQodL/Cnu5gZStlAQbi56bcMcWW2r4UY6WzJ Jz0Y+dIjNvBpWdGooRkDweUxV3havl5n4/R2Rihjc87zYkEFDjc480x4OEEUeFxm7yFF ZGug== Received: by 10.66.76.231 with SMTP id n7mr6136125paw.68.1343402133159; Fri, 27 Jul 2012 08:15:33 -0700 (PDT) MIME-Version: 1.0 Received: by 10.68.25.198 with HTTP; Fri, 27 Jul 2012 08:15:12 -0700 (PDT) In-Reply-To: <1343377148960-4024463.post@n3.nabble.com> References: <1343377148960-4024463.post@n3.nabble.com> From: Michael Gentry Date: Fri, 27 Jul 2012 11:15:12 -0400 Message-ID: Subject: Re: Can default values be set in Constructor instead of setPersistenceState()? To: user@cayenne.apache.org Content-Type: text/plain; charset=ISO-8859-1 X-Gm-Message-State: ALoCoQlnooO+z9Zu+m+DjJVcg7+CZr5V0fCxw5GvQTfeg12oFNLZK5U13XFCg7+OHw2wTU0D4RRF X-Virus-Checked: Checked by ClamAV on apache.org Hi Kanwar, Why are you checking for null? Just set the PK. mrg On Fri, Jul 27, 2012 at 4:19 AM, KM wrote: > I am using Cayenne 3.1B1. > > Overriding onPostAdd is not working. I have added the callback in the > modeller added the code below > > @Override > protected void onPostAdd() > { > if (getObjectId() == null) > { > setLogicalFolderId(UUID.randomUUID().toString()); > } > } > > Basically - trying to initialize the Primary Key - but this is not working. > When adding multiple related objects - id's of the objects obtained through > - context.newObject() are not having any id. > > Can you point me - what am I doing wrong here? > > Thanks > Kanwar Manish > > > Michael Gentry-2 wrote >> >> Hi Joel, >> >> What version of Cayenne are you using? If 3.0, you'll probably want >> to use a callback. If 2.0, use setPersistenceState. For 3.0, you'd >> be interested in the PostAdd callback: >> >> http://cayenne.apache.org/doc30/lifecycle-callbacks.html >> >> Configure the callback in Cayenne Modeler with a name such as >> "onPostAdd" and then in your Java: >> >> @Override >> protected void onPostAdd() >> { >> ... >> } >> >> mrg >> >> >> >> On Thu, Sep 8, 2011 at 11:03 AM, Becker, Joel <joel.becker@> wrote: >>> >>> >>> https://cwiki.apache.org/CAY/setting-initial-values.html says "the best >>> place to set default/initial values in the newly created object is in >>> the setPersistenceState". Is there a problem with setting the default >>> values in a default constructor (following java general best practices)? >>> >>> >> > > > > > -- > View this message in context: http://cayenne.195.n3.nabble.com/Can-default-values-be-set-in-Constructor-instead-of-setPersistenceState-tp3320047p4024463.html > Sent from the Cayenne - User mailing list archive at Nabble.com.