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 385F0200C2B for ; Thu, 2 Mar 2017 09:49:22 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 36E1A160B6F; Thu, 2 Mar 2017 08:49:22 +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 77C04160B61 for ; Thu, 2 Mar 2017 09:49:21 +0100 (CET) Received: (qmail 60676 invoked by uid 500); 2 Mar 2017 08:49:20 -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 60665 invoked by uid 99); 2 Mar 2017 08:49:20 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Mar 2017 08:49:20 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id E3E5118961D for ; Thu, 2 Mar 2017 08:49:19 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.001 X-Spam-Level: * X-Spam-Status: No, score=1.001 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_NONE=-0.0001, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id 5jWQBz8RVaVZ for ; Thu, 2 Mar 2017 08:49:17 +0000 (UTC) Received: from post.selbstdenker.com (mail.selbstdenker.com [81.27.166.251]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id 6059B5FDE0 for ; Thu, 2 Mar 2017 08:49:17 +0000 (UTC) X-CGP-ClamAV-Result: CLEAN X-VirusScanner: Niversoft's CGPClamav Helper v1.19.2 (ClamAV engine v0.99.2) Received: from [81.27.162.170] (account maik@selbstdenker.ag HELO [81.27.162.170]) by selbstdenker.ag (CommuniGate Pro SMTP 6.1.13) with ESMTPSA id 12333058 for user@cayenne.apache.org; Thu, 02 Mar 2017 09:49:11 +0100 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 10.2 \(3259\)) Subject: Re: Validation and @PrePersist From: "Musall, Maik" X-Priority: 3 In-Reply-To: Date: Thu, 2 Mar 2017 09:49:10 +0100 Content-Transfer-Encoding: quoted-printable Message-Id: <142556A5-4160-4ED0-81B7-90B8AC258B92@selbstdenker.ag> References: <93685978-CF98-447B-AA64-D447116E9451@godurkodi.is> <9A9094FD-8298-43F2-A771-8BE48FB48723@godurkodi.is> <43F546FDB3984D94922CFA7ED5855B82@IV5> <1F4BFC9B-B710-46F6-B548-024AFF73ABFD@selbstdenker.ag> To: user@cayenne.apache.org X-Mailer: Apple Mail (2.3259) archived-at: Thu, 02 Mar 2017 08:49:22 -0000 Hi Jurgen, > Am 02.03.2017 um 09:33 schrieb dollj@xsinet.co.za: >=20 > I agree with your reasoning. So then the original description of how = lifecycle events should behave in 3.1 is conceptually better (i.e. that = PrePersist & PreUpdate occur before validation), and the historical = behaviour is then a bug ? That would be my conclusion, too. > It would be good for this to be changed, unless there's backward = compatibility issues :-) Well, there's no better time to change this than at the beginning of M6, = right? :-) Maik >=20 > -----Original Message----- From: Musall, Maik > Sent: Thursday, March 2, 2017 9:53 AM > To: user@cayenne.apache.org > Subject: Re: Validation and @PrePersist >=20 > Hi Jurgen, >=20 > PostAdd is fine for seting a createDate, but what about an updateDate = or something similar? If these assertions are all true: >=20 > 1. validation is supposed to not change attributes > 2. no more changes should be made after validation happened > 3. PrePersist runs after validation >=20 > then there is just no place left to set something like an updateDate. = Also, PrePersist would be restricted to do read-only checks that you can = also do during validation, which makes no sense to me conceptually. >=20 > Maik >=20 >=20 >=20 >> Am 02.03.2017 um 07:56 schrieb dollj@xsinet.co.za: >>=20 >> Hi All >>=20 >> We had a similar discussion Sept-Oct 2012 where it was noted that = there was a discrepancy between the docs and the implementation. That = was with 3.1B where the behaviour was the same as it is now, i.e. = validation occurs before PrePersist (but as noted by Michael the 3.1 = docs incorrectly state "after" ). >>=20 >> So I assume that subsequently the docs were updated for cayenne 4 to = correctly reflect the behaviour. >>=20 >> Back then it was stated that PostAdd was the correct place to do this = kind of thing, which I think is fine for fields that have standard = default values. >>=20 >> It can get a bit clumsy sometimes where you sometimes have to have = both PostAdd and PrePersist doing the same thing. For example for a = timestamp field where object entity creation (PostAdd) occurs much = earlier than the commit (PrePersist), but you want the commit timestamp. = This is where I would have preferred the behaviour that Hugi is looking = for where PrePersist is called first, before validation. >>=20 >> Cheers, >> Jurgen >>=20 >>=20 >> -----Original Message----- From: Michael Gentry >> Sent: Wednesday, March 1, 2017 5:38 PM >> To: Cayenne Users >> Subject: Re: Validation and @PrePersist >>=20 >> Hi Hugi, >>=20 >> I was indeed looking at < 4. No idea why the change was made. = Perhaps >> someone else can answer that one... >>=20 >> Thanks, >>=20 >> mrg >>=20 >>=20 >> On Wed, Mar 1, 2017 at 10:03 AM, Hugi Thordarson = wrote: >>=20 >>> Hi Michael, >>> the documentation was apparently changed for 4.0 in 2015 to reflect = the >>> current behaviour: >>>=20 >>> = https://github.com/apache/cayenne/commit/5bb12cd36f0d87e3b217cdc20c22a0 >>> f6dc9613f3#diff-5b9a57288e30ef9855d80a63a812ec4f >>>=20 >>> Cheers, >>> - hugi >>>=20 >>>=20 >>> > On 1. mar. 2017, at 14:59, Michael Gentry = wrote: >>> > >>> > Hi Hugi, >>> > >>> > If validateForInsert() is being called before PrePersist, we have = a >>> > disconnect between the documentation and the behavior you are = seeing: >>> > >>> > "PrePersist: right before a new object is committed, inside >>> > ObjectContext.commitChanges() and = ObjectContext.commitChangesToParent() >>> > (and prior to validateForInsert())." >>> > >>> > What version of Cayenne are you using? I wonder if something has = > > changed >>> > or if the documentation is just wrong. >>> > >>> > Thanks, >>> > >>> > mrg >>> > >>> > >>> > >>> > On Wed, Mar 1, 2017 at 6:18 AM, Hugi Thordarson = >>> wrote: >>> > >>> >> 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 running >>> >> @PrePersist. >>> >> >>> >> Any suggestions for where I can invoke logic populates required = values >>> >> before validation? >>> >> >>> >> Cheers, >>> >> - hugi >>>=20 >>=20 >=20