Yes, database level foreign key constraints are not compatible with horizontal 
inheritance.  They do work with single table inheritance.  I prefer Single 
Table over Vertical or Horizontal unless I have a specific need for them.  It 
is more efficient and has few issues.  It does bother people who value 
idealistic schemas over efficiency and functionality.  :-)


Chuck



On Nov 20, 2010, at 2:45 PM, Mark Wardle wrote:

> I think i'm being dim. I'll simply remove the db level constraints and hope 
> EOF keeps everything rational. 
> 
> Mark
> 
> -- 
> Dr. Mark Wardle
> Specialist registrar, Neurology
> (Sent from my mobile)
> 
> 
> On 20 Nov 2010, at 22:13, Mark Wardle <m...@wardle.org> wrote:
> 
>> Dear all,
>> 
>> [ Using Wonder with WO54 and PostgreSQL. ]
>> 
>> Is it appropriate to remove foreign key constraints when you get into hairy 
>> and complex webobjects inheritance?
>> 
>> I have an abstract entity Form with many subentities using horizontal 
>> inheritance.
>> 
>> This has worked perfectly and I have subentities representing various 
>> structured and unstructured data collection forms as well as medical 
>> investigation results. 
>> 
>> I also have an abstract entity Annotation and a number of concrete 
>> subentities to add additional optional data to a form. 
>> 
>> There is a to-many relationship between the abstract entity Form (db table: 
>> t_form) and the abstract entity Annotation (db table: t_annotation). There 
>> is logic to create concrete instances of subentities of the correct type and 
>> link appropriate annotation subentities to the appropriate form subentity.
>> 
>> I keep getting exceptions due to foreign key constraints. I suspect my 
>> solution is to remove these but I had assumed there would be some magic 
>> going on within EOF to handle this. I *thought* the topmost entity's primary 
>> key sequence generator would be used for all subentities?
>> 
>> 
>>              EOEditingContext ec = ERXEC.newEditingContext();
>>              Patient pt = Patient.fetchPatient(ec, 
>> Patient.PATIENT_IDENTIFIER.eq(7271L));
>>              NSArray<Encounter> encounters = pt.encounters(null, 
>> Encounter.DATE_TIME.descs(), false);
>>              Encounter e = encounters.get(0);
>>              
>>              FormResultMriBrain fr = (FormResultMriBrain) 
>> EOUtilities.createAndInsertInstance(ec, FormResultMriBrain.ENTITY_NAME);
>>              fr.setUser(User.fetchRequiredUser(ec, User.USERNAME_KEY, 
>> "mark"));
>>              fr.setDatePerformed(new NSTimestamp());
>>              fr.setDateReported(new NSTimestamp());
>>              fr.setReport("A normal scan");
>>              e.addToForms(fr);
>>              
>>              AnnotationMriBrainAtaxia ataxia = (AnnotationMriBrainAtaxia) 
>> EOUtilities.createAndInsertInstance(ec, 
>> AnnotationMriBrainAtaxia.ENTITY_NAME);
>>              ataxia.setForm(fr);
>>              ataxia.setDateCreated(new NSTimestamp());
>>              ataxia.setCerebellarAtrophy(false);
>>              ataxia.setCerebralAtrophy(false);
>>              ataxia.setLeucodystrophy(false);
>>              ataxia.setPontineAtrophy(false);
>>              ataxia.setUser(fr.user());
>>              
>>              AnnotationMriBrainMultipleSclerosis annotation = 
>> (AnnotationMriBrainMultipleSclerosis) 
>> EOUtilities.createAndInsertInstance(ec, 
>> AnnotationMriBrainMultipleSclerosis.ENTITY_NAME);
>>              annotation.setForm(fr);
>>              annotation.setUser(fr.user());
>>              ec.saveChanges();
>> 
>> 
>> And this is my log file: [apologies for the terribly long entity and table 
>> names]
>> 
>> 
>> Nov 20 21:59:49 RSNews[52700] DEBUG com.eldrix.rsdb.model._Form  - updating 
>> dateCreated from null to 2010-11-20 21:59:49 Etc/GMT
>> Nov 20 21:59:49 RSNews[52700] DEBUG com.eldrix.rsdb.model._FormResult  - 
>> updating dataSourceType from null to MANUAL
>> Nov 20 21:59:49 RSNews[52700] DEBUG 
>> com.eldrix.rsdb.model._FormResultMriBrain  - updating withGadolinium from 
>> null to false
>> Nov 20 21:59:49 RSNews[52700] DEBUG com.eldrix.rsdb.model._FormResult  - 
>> updating datePerformed from null to 2010-11-20 21:59:49 Etc/GMT
>> Nov 20 21:59:49 RSNews[52700] DEBUG com.eldrix.rsdb.model._FormResult  - 
>> updating dateReported from null to 2010-11-20 21:59:49 Etc/GMT
>> Nov 20 21:59:49 RSNews[52700] DEBUG 
>> com.eldrix.rsdb.model._FormResultMriBrain  - updating report from null to A 
>> normal scan
>> Nov 20 21:59:50 RSNews[52700] DEBUG com.eldrix.rsdb.model._Annotation  - 
>> updating dateCreated from null to 2010-11-20 21:59:50 Etc/GMT
>> Nov 20 21:59:50 RSNews[52700] DEBUG 
>> com.eldrix.rsdb.model._AnnotationMriBrainAtaxia  - updating 
>> cerebellarAtrophy from null to false
>> Nov 20 21:59:50 RSNews[52700] DEBUG 
>> com.eldrix.rsdb.model._AnnotationMriBrainAtaxia  - updating cerebralAtrophy 
>> from null to false
>> Nov 20 21:59:50 RSNews[52700] DEBUG 
>> com.eldrix.rsdb.model._AnnotationMriBrainAtaxia  - updating leucodystrophy 
>> from null to false
>> Nov 20 21:59:50 RSNews[52700] DEBUG 
>> com.eldrix.rsdb.model._AnnotationMriBrainAtaxia  - updating pontineAtrophy 
>> from null to false
>> Nov 20 21:59:50 RSNews[52700] DEBUG er.eo.ERXGenericRecord  - 
>> EditingContextWillSaveChanges: done calling will*
>> Nov 20 21:59:50 RSNews[52700] WARN  NSLog  - A fatal exception occurred: 
>> ERROR: insert or update on table "t_annotation_mri_brain_ataxia" violates 
>> foreign key constraint "t_annotation_mri_brain_ataxia_form_fk_id_fk"
>>   Detail: Key (form_fk)=(29) is not present in table "t_form".
>> [2010-11-20 21:59:50 GMT] <main> ERROR: insert or update on table 
>> "t_annotation_mri_brain_ataxia" violates foreign key constraint 
>> "t_annotation_mri_brain_ataxia_form_fk_id_fk"
>>   Detail: Key (form_fk)=(29) is not present in table "t_form".at 
>> org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2062)
>> at 
>> org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1795)
>> at 
>> org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
>> at 
>> org.postgresql.jdbc2.AbstractJdbc2Connection.executeTransactionCommand(AbstractJdbc2Connection.java:671)
>> at 
>> org.postgresql.jdbc2.AbstractJdbc2Connection.commit(AbstractJdbc2Connection.java:691)
>> at 
>> com.webobjects.jdbcadaptor.JDBCContext.commitTransaction(JDBCContext.java:452)
>> at 
>> com.webobjects.eoaccess.EODatabaseContext.commitChanges(EODatabaseContext.java:6303)
>> at 
>> com.webobjects.eocontrol.EOObjectStoreCoordinator.saveChangesInEditingContext(EOObjectStoreCoordinator.java:386)
>> at 
>> com.webobjects.eocontrol.EOEditingContext.saveChanges(EOEditingContext.java:3192)
>> at er.extensions.eof.ERXEC._saveChanges(ERXEC.java:1085)
>> at er.extensions.eof.ERXEC.saveChanges(ERXEC.java:1007)
>> at com.eldrix.news.app.Application.<init>(Application.java:83)
>> at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>> at 
>> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
>> at 
>> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
>> at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
>> at java.lang.Class.newInstance0(Class.java:355)
>> at java.lang.Class.newInstance(Class.java:308)
>> at com.webobjects.appserver.WOApplication.main(WOApplication.java:547)
>> at er.extensions.appserver.ERXApplication.main(ERXApplication.java:783)
>> at com.eldrix.news.app.Application.main(Application.java:41)
>> 
>> 
>>      at 
>> com.webobjects.jdbcadaptor.JDBCContext.commitTransaction(JDBCContext.java:455)
>>      at 
>> com.webobjects.eoaccess.EODatabaseContext.commitChanges(EODatabaseContext.java:6303)
>>      at 
>> com.webobjects.eocontrol.EOObjectStoreCoordinator.saveChangesInEditingContext(EOObjectStoreCoordinator.java:386)
>>      at 
>> com.webobjects.eocontrol.EOEditingContext.saveChanges(EOEditingContext.java:3192)
>>      at er.extensions.eof.ERXEC._saveChanges(ERXEC.java:1085)
>>      at er.extensions.eof.ERXEC.saveChanges(ERXEC.java:1007)
>>      at com.eldrix.news.app.Application.<init>(Application.java:83)
>>      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>>      at 
>> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
>>      at 
>> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
>>      at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
>>      at java.lang.Class.newInstance0(Class.java:355)
>>      at java.lang.Class.newInstance(Class.java:308)
>>      at com.webobjects.appserver.WOApplication.main(WOApplication.java:547)
>>      at er.extensions.appserver.ERXApplication.main(ERXApplication.java:783)
>>      at com.eldrix.news.app.Application.main(Application.java:41)
>> 
>> 
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/webobjects-dev/chill%40global-village.net
> 
> This email sent to ch...@global-village.net

-- 
Chuck Hill             Senior Consultant / VP Development

Practical WebObjects - for developers who want to increase their overall 
knowledge of WebObjects or who are trying to solve specific problems.    
http://www.global-village.net/products/practical_webobjects







Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to