Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id E15A6200C2A for ; Wed, 1 Mar 2017 20:32:08 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id DE550160B70; Wed, 1 Mar 2017 19:32:08 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 30489160B56 for ; Wed, 1 Mar 2017 20:32:08 +0100 (CET) Received: (qmail 46250 invoked by uid 500); 1 Mar 2017 19:32:07 -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 46234 invoked by uid 99); 1 Mar 2017 19:32:07 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Mar 2017 19:32:07 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 91822C05AA for ; Wed, 1 Mar 2017 19:32:06 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.398 X-Spam-Level: ** X-Spam-Status: No, score=2.398 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_SORBS_SPAM=0.5, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd4-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id 4NN9lqRDbBx7 for ; Wed, 1 Mar 2017 19:32:04 +0000 (UTC) Received: from mail-ua0-f176.google.com (mail-ua0-f176.google.com [209.85.217.176]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id 4DD4D5FB61 for ; Wed, 1 Mar 2017 19:32:04 +0000 (UTC) Received: by mail-ua0-f176.google.com with SMTP id 72so51275167uaf.3 for ; Wed, 01 Mar 2017 11:32:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=cnMXF5PpXWmffrwEpi4dVWxiSbdrJ72oYuDJeA4Ffxg=; b=vHy54IxanYMGEe/3cr/H4AMIyIFTnIlEUp1FPfCxjt0MO18OpJWLjgcLJsbSjm6KD0 MnzncVugu6h/eqv+H7iGk4QT0FM/8wsBoHs+NwehRkrIN1yVuqWDGSwNkZ7S+3XjU7Cn 1gT6F++z4nusdUsADKrrUAYomT/DyC4Joh/Xc9kX0CsBYilWChtM3EHm1/uUX38F9fRV hZjj6NADFqLOfOoHigBMDvOivKW3Usjq4RFcJd+Ik3bmIM5R8tNGFm22rJrpWfx8t85K JFJfOl3s2BxctSPItZXE8JWH1I9L5zJkUbRwlZciUWHilox0WB6Yhqt1wiSkNbN40lml SsIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=cnMXF5PpXWmffrwEpi4dVWxiSbdrJ72oYuDJeA4Ffxg=; b=jBW2bgPItezhB9WnEALwS3+o/0L6lTf/nxPD5HUkhPpB219s2oyK+sVl6C1ML0AEUq lLWIwaXZKBYauRjz8pkKo9ov214Iu5CiQHVZdrm/Kjsz1XUwrR4mKVkTKq8MlVBBwseG 534AJecbVJlib41r21nhZM4rilWwpmHs4FzKKeK++C6F+mebqVkPNoxrzaCZ985d0Avr Qz3KNHsWQiohY8oORy8BfdAhrYsjam8vVAwEacHpNMw1EDop2vAIFs6Sr6BtH3on44V1 BRyMWHTw5eNEm3or3cz9imQDoYgmRdnxyBOmwCdJAweidl2+WDOjK6hWlMu+TCv+4HPj vCoA== X-Gm-Message-State: AMke39k2Cut9X9iiu08PpuO0o1qOTd3+pwRcds5ZYXJuyvoZx8EYeQa/4Bw1tlytGtMTJug7YjNId3uKCcklgw== X-Received: by 10.176.74.209 with SMTP id t17mr4744381uae.176.1488396719713; Wed, 01 Mar 2017 11:31:59 -0800 (PST) MIME-Version: 1.0 Received: by 10.103.77.140 with HTTP; Wed, 1 Mar 2017 11:31:29 -0800 (PST) In-Reply-To: References: <93685978-CF98-447B-AA64-D447116E9451@godurkodi.is> <2F0E894D9C1C4E45B3128748AAD0C049@IV5> <59917604-F39B-493D-80BF-370697EE5244@godurkodi.is> <52F57598-3432-46B9-B7B3-6D7F9D6E1458@swarmbox.com> From: Michael Gentry Date: Wed, 1 Mar 2017 14:31:29 -0500 Message-ID: Subject: Re: Validation and @PrePersist To: Cayenne Users Content-Type: multipart/alternative; boundary=f403045f83f6c3773e0549b05d84 archived-at: Wed, 01 Mar 2017 19:32:09 -0000 --f403045f83f6c3773e0549b05d84 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Maik, I've historically done data manipulations in the lifecycle events (pre-persist, post-add, post-load, etc) and not the validate methods. I kind of agree with you that validate shouldn't be modifying data. I'm hoping someone else explains the change now. :-) mrg On Wed, Mar 1, 2017 at 11:43 AM, Musall, Maik wrote: > Hi all, > > but isn't hte purpose of validation to check if the object to be saved is > in a valid state? That would imply that validation has a positive (pass) = or > negative (ValidationException) result, and no side effects. Modifying the > object during validation would defeat the purpose, wouldn't it? > > Maik > > > Am 01.03.2017 um 17:12 schrieb Matt Watson : > > > > When I ran into this same scenario I realized that =E2=80=9CvalidateFor= Insert=E2=80=9D > was the hook I needed, instead of @PrePersist. > > > > @Override > > public void validateForInsert(ValidationResult validationResult) { > > if (getReference() =3D=3D null || getReference().isEmpty()) { > > setReference(System.getNextPurchaseOrderReference()); > > } > > super.validateForInsert(validationResult); > > } > > > > > > > >> On Mar 1, 2017, at 5:51 AM, Hugi Thordarson wrote: > >> > >> Hi Jurgen, > >> fine suggestion but unfortunately not the part of the lifecycle I need > to catch=E2=80=94the action needs to be performed before committing, not = after > adding (so basically I need @PrePersist=E2=80=94but I need it before vali= dation > happens). > >> > >> Cheers, > >> - hugi > >> > >> > >>> On 1. mar. 2017, at 13:14, > wrote: > >>> > >>> Hi Hugi > >>> > >>> For this kind of thing use @PostAdd instead. > >>> > >>> Regards > >>> Jurgen > >>> > >>> > >>> -----Original Message----- From: Hugi Thordarson > >>> Sent: Wednesday, March 1, 2017 1:18 PM > >>> To: user@cayenne.apache.org > >>> Subject: Validation and @PrePersist > >>> > >>> Hi all, > >>> I have some logic in a Listener that uses @PrePersist to populate the > value of a required attribute before committing changes. Turns out this > doesn=E2=80=99t work, since Cayenne invokes validateForInsert() before ru= nning > @PrePersist. > >>> > >>> Any suggestions for where I can invoke logic populates required value= s > before validation? > >>> > >>> Cheers, > >>> - hugi > >> > > > > --f403045f83f6c3773e0549b05d84--