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: "Walter Lo Nigro" Received: from smtpweb146.aruba.it ([62.149.158.146] verified) by post.selbstdenker.com (CommuniGate Pro SMTP 6.3.3) with ESMTP id 26126341 for webobjects-dev@wocommunity.org; Thu, 08 Jul 2021 07:31:23 +0200 Received-SPF: none receiver=post.selbstdenker.com; client-ip=62.149.158.146; envelope-from=walter@lonigro.net Received: from mbp-di-walter.homenet.telecomitalia.it ([79.30.239.47]) by Aruba Outgoing Smtp with ESMTPA id 1McnmHxZxmkLG1McnmHmis; Thu, 08 Jul 2021 07:31:02 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=aruba.it; s=a1; t=1625722262; bh=MLJuTwptlDRuH4YhzfPJzTxHl79OXCxHOxuWz8KR37I=; h=From:Content-Type:Mime-Version:Subject:Date:To; b=AKkS8fZas6Falole9bNdSkEXzomkFNUK3KDsKqUlk50V9fGUxXyCKTXgjHvmYrWF7 +WeAnlgv5EzNLx98sm7eG3NBABJf/Sbjf1eB+MwqO6bidgTQaSYGV3Sh7BW+3bHwcd 6Y/9irTkwBSlBotg/3bxVAJgHnDknEEASvU4juzWiB9E2uZ98ekEWJO/M1b7LALYYW qvc4Z5wvKSipUJLbn0ROBTfLV6vK2Q40bHD0F9rXxFBzclB0uye4TXmdIgtH9XXBtA UIwGkAr1XTzEf/LCUHFr9ahCbCuuxFwaTK8PHiFnNRUrd99VYkJo4vGf/wCaH0oIXM cwKgG+jAkK+yg== Content-Type: multipart/alternative; boundary="Apple-Mail=_353A23E4-9EE8-4AB8-BF84-16C003ABE412" Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.7\)) Subject: Re: [WO-DEV] Very stupid question re: One-to-many, single table inheritance in D2W ERModernLook Date: Thu, 8 Jul 2021 07:31:01 +0200 References: To: WebObjects & WOnder Development In-Reply-To: Message-Id: X-Mailer: Apple Mail (2.3445.9.7) X-CMAE-Envelope: MS4wfHhpeZMRYFhOYs2HboQV6mPBhctgkH18oegncbjvFzMsfBkD4t7jFcBFUNKr0uEXLKCH/vASxOshmrl3vWLUnbuRHp+KoI8+2mvk+ERF0YeN4dXJ7LYY rjOF1qOZrNtas+GheKksxi+b8tvhQM3dkdToT71CtsCBAI2a0ZdkWrMmFr7xpWhj2AfVSIypR94ARWL5IDS705AFyhQNaudifqM= --Apple-Mail=_353A23E4-9EE8-4AB8-BF84-16C003ABE412 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Thank you Ralf, that was it. I=E2=80=99ve been away from WO and Wonder = for more than 10 years, and forgot quite a lot. Seems I=E2=80=99ll have = to get back to Chuck=E2=80=99s book and Wonder source... Again, thank you very much. Walter *** Walter Lo Nigro, Trieste, Italy - http://www.wln.it *** *** Choral Activities, "G. Tartini" Conservatory, Trieste *** *** Freelance conductor, RiscOS/ROOL registered developer *** > Il giorno 06 lug 2021, alle ore 17:55, Ralf Schuchardt = ha scritto: >=20 > Hi Walter, >=20 > maybe I can explain the problem you are seeing. >=20 > In `awakeFromInsertion` you create a new Qualifica object. >=20 > Qualifica qual =3D new Qualifica(); > eo.insertObject(qual); >=20 > 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 internal table) to assign the new primary key for this new object. > But as you have already inserted some values to Qualifica the sequence = generation is probably out of sync with the already inserted values. = Therefore you get a duplicate key error when using the sequence values = in the new object. > To solve this you may need to update the Qualifica sequence (if used = by EOF) with the greatest id value already used in Qualifica. >=20 > But I don=E2=80=99t know, why you even create a new Qualifica object = in `awakeFromInsertion`, as setting the qualifica relationship already = assigns one in `createStudente`. > If you want to insert it as a default value, it may be better to fetch = the existing one: >=20 > public void awakeFromInsertion(EOEditingContext ec) { > super.awakeFromInsertion(ec); > Qualifica qual =3D Qualifica.fetchRequiredQualifica(ec, = Qualifica.TIPO.eq("studente=E2=80=9C)); > this.setQualificaRelationship(qual); > } >=20 > If you are using Wonder you may also want to use the = init(EOEditingContext) method instead of awakeFormInsertion. >=20 > Ralf >=20 > On 6 Jul 2021, at 15:37, Walter Lo Nigro wrote: >=20 >> Hi everybody, >>=20 >> I just resolved to write to the list, obviouly risking any sort of = ominously nefast/sarcastic comments=E2=80=A6 (please be kind). >>=20 >> 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. >>=20 >> 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 inheritance. >> I set up a further entity =E2=80=98Qualifica=E2=80=99 with just one = column =E2=80=99tipo', and I populate it with some values (just = =E2=80=9Cstudente=E2=80=9D for a start), and use it merely as a lookup = table for Utente and Studente via a One-to-many relationship: >>=20 >> Utente.qualifica.tipo << - > Qualifica.tipo >>=20 >> Utente has also a key =E2=80=98tipo=E2=80=99 which is the flattened = relationship between Utente and Qualifica. >> Obviously same for Studente, which also have a qualifier: tipo =3D = =E2=80=9Cstudente=E2=80=9D. >>=20 >> For Studente I have added something to preset value of tipo =3D = =E2=80=9Cstudente=E2=80=9D, here is the extended class definition (which = inherits from _Studente, which of course inherits from _Utente base = class): >>=20 >> public class Studente extends _Studente { >> @SuppressWarnings("unused") >> private static final Logger log =3D = LoggerFactory.getLogger(Studente.class); >>=20 >> 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()); >> } >>=20 >> public static Studente createStudente(EOEditingContext = editingContext, String nome, your.app.model.Qualifica qualifica) { >> Studente eo =3D (Studente) = EOUtilities.createAndInsertInstance(editingContext, = _Studente.ENTITY_NAME); >> eo.setNome(nome); // (n.b. the only other attribute in = Utente/Studente) >> eo.setQualificaRelationship(qualifica); >> return eo; >> } >> } >>=20 >> Everything seems ok but, when I try and create a new Studente object = (having already inserted a =E2=80=9Cstudente=E2=80=9D row into = Qualifica), I get the following error: >>=20 >> com.webobjects.eoaccess.EOGeneralAdaptorException: EvaluateExpression = failed: : 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. >>=20 >> In Properties I have: >> # EOF >> er.extensions.ERXEC.safeLocking=3Dtrue >> er.extensions.ERXEC.useSharedEditingContext=3Dfalse >> = er.extensions.ERXEnterpriseObject.applyRestrictingQualifierOnInsert=3Dfals= e >> er.extensions.ERXEnterpriseObject.updateInverseRelationships=3Dfalse >>=20 >> Which is the best method to avoid the database server trying to = update BOTH sides of relationship? I am using Postgresql. >>=20 >> Please help (and have mercy on me). Thank you. >>=20 >>=20 >> *** Walter Lo Nigro, Trieste, Italy - http://www.wln.it *** >> *** Choral Activities, "G. Tartini" Conservatory, Trieste *** >> *** Freelance conductor, RiscOS/ROOL registered developer *** >>=20 >>=20 >> ############################################################# >> 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 = >=20 > ############################################################# > 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 = >=20 --Apple-Mail=_353A23E4-9EE8-4AB8-BF84-16C003ABE412 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Thank= you Ralf, that was it. I=E2=80=99ve been away from WO and Wonder for = more than 10 years, and forgot quite a lot. Seems I=E2=80=99ll have to = get back to Chuck=E2=80=99s book and Wonder source...

Again, thank you very much.
Walter

***  Walter Lo Nigro, Trieste, Italy =  -  http://www.wln.it  ***
*** =  Choral Activities, "G. Tartini" Conservatory, Trieste =  ***
***  Freelance conductor, = RiscOS/ROOL registered developer  ***

Il giorno 06 lug 2021, alle ore 17:55, Ralf Schuchardt <webobjects-dev@wocommunity.org> ha scritto:

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 internal table) to assign the new primary = key for this new object.
But as you have already inserted = some values to Qualifica the sequence generation is probably out of sync = with the already inserted values. Therefore you get a duplicate key = error when using the sequence values in the new object.
To = solve this you may need to update the Qualifica sequence (if used by = EOF) 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 assigns one in `createStudente`.
If = you want to insert it as a default value, it may be better to fetch the = existing one:

public void = awakeFromInsertion(EOEditingContext ec) {
= super.awakeFromInsertion(ec);
Qualifica = qual =3D Qualifica.fetchRequiredQualifica(ec, = Qualifica.TIPO.eq("studente=E2=80=9C));
= this.setQualificaRelationship(qual);
}

If you are using Wonder you may also want to = use the init(EOEditingContext) 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 ominously 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 = inheritance.
I set up a further entity =E2=80=98Qualifica=E2= =80=99 with just one column =E2=80=99tipo', and I populate it with some = values (just =E2=80=9Cstudente=E2=80=9D for a start), and use it merely = as a lookup table for Utente 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 relationship = 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=9Cstudente=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.class);

= 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(editingContext, = _Studente.ENTITY_NAME);
eo.setNome(nome); // (n.b. the = only other attribute in Utente/Studente)
= eo.setQualificaRelationship(qualifica);
return = eo;
}
}
Everything seems ok but, when I try and create a new = Studente object (having already inserted a =E2=80=9Cstudente=E2=80=9D = row into Qualifica), I get the following error:

com.webobjects.eoaccess.EOGeneralAdaptorException: = EvaluateExpression failed: = <com.webobjects.jdbcadaptor.PostgresqlExpression: "INSERT INTO = Qualifica(id, tipo) VALUES (?::int4, ?::varchar(50))" withBindings: = 1:4(id), 2:"studente"(tipo)>: 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.applyRestrictingQualifierOnIn= sert=3Dfalse
er.extensions.ERXEnterpriseObject.updateInverseRelationships=3D= false

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 <webobjects-dev@wocommunity.org>.
To = unsubscribe, E-mail to: <webobjects-dev-off@wocommunity.org>
To = switch to the DIGEST mode, E-mail to <webobjects-dev-digest@wocommunity.org>
To = switch to the INDEX mode, E-mail to <webobjects-dev-index@wocommunity.org>
Send= administrative queries to  <webobjects-dev-request@wocommunity.org>

#############################################################This message is sent to you because you are subscribed = to
 the mailing list <webobjects-dev@wocommunity.org>.
To = unsubscribe, E-mail to: <webobjects-dev-off@wocommunity.org>
To = switch to the DIGEST mode, E-mail to <webobjects-dev-digest@wocommunity.org>
To = switch to the INDEX mode, E-mail to <webobjects-dev-index@wocommunity.org>
Send= administrative queries to  <webobjects-dev-request@wocommunity.org>


= --Apple-Mail=_353A23E4-9EE8-4AB8-BF84-16C003ABE412--