Mailing List webobjects-dev@wocommunity.org Message #230
From: Walter Lo Nigro <webobjects-dev@wocommunity.org>
Subject: Very stupid question re: One-to-many, single table inheritance in D2W ERModernLook
Date: Tue, 6 Jul 2021 15:37:54 +0200
To: WebObjects & WOnder Development <webobjects-dev@wocommunity.org>
Hi everybody,

I just resolved to write to the list, obviouly risking any sort of ominously nefast/sarcastic comments… (please be kind).

I am struggling with a very simple situation, and I’m sure I’m missing something basic. I apologize for that.

I have a generic entity ‘Utente’, and another one ‘Studente’ which inherits from the first one via single-table inheritance.
I set up a further entity ‘Qualifica’ with just one column ’tipo', and I populate it with some values (just “studente” 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 ‘tipo’ which is the flattened relationship between Utente and Qualifica.
Obviously same for Studente, which also have a qualifier: tipo = “studente”.

For Studente I have added something to preset value of tipo = “studente”, 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 = LoggerFactory.getLogger(Studente.class);

public void awakeFromInsertion(EOEditingContext eo) {
super.awakeFromInsertion(eo);
Qualifica qual = 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 = (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 “studente” 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)=(4) already exists.

In Properties I have:
# EOF
er.extensions.ERXEC.safeLocking=true
er.extensions.ERXEC.useSharedEditingContext=false
er.extensions.ERXEnterpriseObject.applyRestrictingQualifierOnInsert=false
er.extensions.ERXEnterpriseObject.updateInverseRelationships=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  ***

Subscribe (FEED) Subscribe (DIGEST) Subscribe (INDEX) Unsubscribe Mail to Listmaster