X-CGP-ClamAV-Result: CLEAN X-VirusScanner: Niversoft's CGPClamav Helper v1.22.2a (ClamAV engine v0.102.2) X-Junk-Score: 0 [] X-KAS-Score: 0 [] From: "Ralf Schuchardt" Received: from mout.gmx.net ([212.227.17.22] verified) by selbstdenker.ag (CommuniGate Pro SMTP 6.3.3) with ESMTPS id 26117238 for webobjects-dev@wocommunity.org; Tue, 06 Jul 2021 17:56:09 +0200 Received-SPF: pass receiver=post.selbstdenker.com; client-ip=212.227.17.22; envelope-from=rasc@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1625586949; bh=hdE4dIFbSirgVR/3DJN6zGB9SzqfTVRI9yV+W38LRQ4=; h=X-UI-Sender-Class:From:To:Subject:Date:In-Reply-To:References; b=SCstNqdMoG0pjvLjLuMvp+NilRE97yWrAZDuj1xv2qquoJQZSmMJqrlrS7aGKYGX7 pihoXGob2m7xW3+EJuFDKIEoEYFKR8YOvA7n6+4M+b0w+bg13ydDgBMBObztlEBMfR gw8C+G+HwnOUgco9eSyRXK/B+eb4VQ1VqF3uWoCw= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.42.66] ([193.142.190.210]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1Mg6Zq-1lXl4U3efe-00hia7 for ; Tue, 06 Jul 2021 17:55:48 +0200 To: "WebObjects & WOnder Development" Subject: Re: [WO-DEV] Very stupid question re: One-to-many, single table inheritance in D2W ERModernLook Date: Tue, 06 Jul 2021 17:55:04 +0200 X-Mailer: MailMate (1.14r5807) Message-ID: <1EC37595-3226-4303-823A-C5113429D059@gmx.de> In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:J4VLeh9PRVBzqPeDGVE6yWjz1dsGzueOTZAErJ/iCp5n3Yh966f 6K3DlfSrE1tsI1YE4gVY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UMKBsdnweaUvGBAe5fp8yN5VWp jY1B+GShR/UREi9oEzu+nj5Nhbn5QR87mMBpHid4qm2hXZYyRmDz+0LgWWU1VOCM27+JOZCIb XVIMGUUDcu8jK9y8BHaS8YG9VPhMig78+wlw5zHThUelvLOuitZyAKtHTkDKEChK4TFVxvcDs b+7gAVjZfUP9kkoatGDz64XWWxWbxxjK3n4q/RJWCp/tiNOtk6X1yRWjFc4qActiFmboEiFTK YX0C9ylJd+rw84BKrMyrvydxMnth/Cbjeib Hi Walter, maybe I can explain the problem you are seeing. In `awakeFromInsertion` you create a new Qualifica object. Qualifica qual =3D new Qualifica(); eo.insertObject(qual); This Qualifica object has an `id` attribute probably of type `serial` or = maybe an `int4` with an attached sequence. EOF uses the sequence (or an i= nternal table) to assign the new primary key for this new object. But as you have already inserted some values to Qualifica the sequence ge= neration is probably out of sync with the already inserted values. Theref= ore you get a duplicate key error when using the sequence values in the n= ew object. To solve this you may need to update the Qualifica sequence (if used by E= OF) with the greatest id value already used in Qualifica. But I don=E2=80=99t know, why you even create a new Qualifica object in `= awakeFromInsertion`, as setting the qualifica relationship already assign= s one in `createStudente`. If you want to insert it as a default value, it may be better to fetch th= e existing one: public void awakeFromInsertion(EOEditingContext ec) { super.awakeFromInsertion(ec); Qualifica qual =3D Qualifica.fetchRequiredQualifica(ec, Qualifica.TIPO.e= q("studente=E2=80=9C)); this.setQualificaRelationship(qual); } If you are using Wonder you may also want to use the init(EOEditingContex= t) method instead of awakeFormInsertion. Ralf On 6 Jul 2021, at 15:37, Walter Lo Nigro wrote: > Hi everybody, > > I just resolved to write to the list, obviouly risking any sort of omin= ously nefast/sarcastic comments=E2=80=A6 (please be kind). > > I am struggling with a very simple situation, and I=E2=80=99m sure I=E2= =80=99m missing something basic. I apologize for that. > > I have a generic entity =E2=80=98Utente=E2=80=99, and another one =E2=80= =98Studente=E2=80=99 which inherits from the first one via single-table i= nheritance. > I set up a further entity =E2=80=98Qualifica=E2=80=99 with just one col= umn =E2=80=99tipo', and I populate it with some values (just =E2=80=9Cstu= dente=E2=80=9D for a start), and use it merely as a lookup table for Uten= te and Studente via a One-to-many relationship: > > Utente.qualifica.tipo << - > Qualifica.tipo > > Utente has also a key =E2=80=98tipo=E2=80=99 which is the flattened rel= ationship between Utente and Qualifica. > Obviously same for Studente, which also have a qualifier: tipo =3D =E2=80= =9Cstudente=E2=80=9D. > > For Studente I have added something to preset value of tipo =3D =E2=80=9C= studente=E2=80=9D, here is the extended class definition (which inherits = from _Studente, which of course inherits from _Utente base class): > > public class Studente extends _Studente { > @SuppressWarnings("unused") > private static final Logger log =3D LoggerFactory.getLogger(Studente.c= lass); > > public void awakeFromInsertion(EOEditingContext eo) { > super.awakeFromInsertion(eo); > Qualifica qual =3D new Qualifica(); > eo.insertObject(qual); > qual.setTipo("studente"); > this.setQualifica(qual); > this.setTipo(qual.tipo()); > } > > public static Studente createStudente(EOEditingContext editingContext,= String nome, your.app.model.Qualifica qualifica) { > Studente eo =3D (Studente) EOUtilities.createAndInsertInstance(editin= gContext, _Studente.ENTITY_NAME); > eo.setNome(nome); // (n.b. the only other attribute in Utente/Student= e) > eo.setQualificaRelationship(qualifica); > return eo; > } > } > > Everything seems ok but, when I try and create a new Studente object (h= aving already inserted a =E2=80=9Cstudente=E2=80=9D row into Qualifica), = I get the following error: > > com.webobjects.eoaccess.EOGeneralAdaptorException: EvaluateExpression f= ailed: : Next exception:SQL State:23505 -- error code: 0 -- = msg: ERROR: duplicate key value violates unique constraint "qualifica_pk"= Dettaglio: Key (id)=3D(4) already exists. > > In Properties I have: > # EOF > er.extensions.ERXEC.safeLocking=3Dtrue > er.extensions.ERXEC.useSharedEditingContext=3Dfalse > er.extensions.ERXEnterpriseObject.applyRestrictingQualifierOnInsert=3Df= alse > er.extensions.ERXEnterpriseObject.updateInverseRelationships=3Dfalse > > Which is the best method to avoid the database server trying to update = BOTH sides of relationship? I am using Postgresql. > > Please help (and have mercy on me). Thank you. > > > *** Walter Lo Nigro, Trieste, Italy - http://www.wln.it *** > *** Choral Activities, "G. Tartini" Conservatory, Trieste *** > *** Freelance conductor, RiscOS/ROOL registered developer *** > > > ############################################################# > This message is sent to you because you are subscribed to > the mailing list . > To unsubscribe, E-mail to: > To switch to the DIGEST mode, E-mail to > To switch to the INDEX mode, E-mail to > Send administrative queries to