Hi all,
I am trying to use Glorp to map a simple class model into a database. I am using VW 7.7.1 nc. This is my model: AcademiaPublication with instance variables: id, name, content AcademiaConferencePaper (subclass of AcademiaPublication) with instance variables: venue, isShort AcademiaBookChapter (subclass of AcademiaPublication) with instance variables: chapterNumber. These are all the methods defined in "AcademiaTestsDescriptor," my descriptor: ===code snippet=== AcademiaTestsDescriptor>>allTableNames ^#('ACADEMIAPUBLICATION') AcademiaTestsDescriptor>>constructAllClasses ^(super constructAllClasses) asSet add: AcademiaBookChapter; add: AcademiaConferencePaper; add: AcademiaPublication; yourself AcademiaTestsDescriptor>>descriptorForAcademiaBookChapter: aDescriptor | table | table := self tableNamed: 'ACADEMIAPUBLICATION'. aDescriptor table: table. aDescriptor addMapping: (DirectMapping from: #id to: (table fieldNamed: 'ID')). aDescriptor addMapping: (DirectMapping from: #content to: (table fieldNamed: 'CONTENT')). aDescriptor addMapping: (DirectMapping from: #name to: (table fieldNamed: 'NAME')). (self typeResolverFor: AcademiaBookChapter) register: aDescriptor keyedBy: 'AcademiaBookChapter' field: (table fieldNamed: 'CLASSTYPE'). aDescriptor addMapping: (DirectMapping from: #chapterNumber to: (table fieldNamed: 'CHAPTERNUMBER')). ^self AcademiaTestsDescriptor>>descriptorForAcademiaConferencePaper: aDescriptor | table | table := self tableNamed: 'ACADEMIAPUBLICATION'. aDescriptor table: table. aDescriptor addMapping: (DirectMapping from: #id to: (table fieldNamed: 'ID')). aDescriptor addMapping: (DirectMapping from: #content to: (table fieldNamed: 'CONTENT')). aDescriptor addMapping: (DirectMapping from: #name to: (table fieldNamed: 'NAME')). (self typeResolverFor: AcademiaConferencePaper) register: aDescriptor keyedBy: 'AcademiaConferencePaper' field: (table fieldNamed: 'CLASSTYPE'). aDescriptor addMapping: (DirectMapping from: #isShort to: (table fieldNamed: 'ISSHORT')). aDescriptor addMapping: (DirectMapping from: #venue to: (table fieldNamed: 'VENUE')). ^self AcademiaTestsDescriptor>>descriptorForAcademiaPublication: aDescriptor | table | table := self tableNamed: 'ACADEMIAPUBLICATION'. aDescriptor table: table. aDescriptor addMapping: (DirectMapping from: #id to: (table fieldNamed: 'ID')). aDescriptor addMapping: (DirectMapping from: #content to: (table fieldNamed: 'CONTENT')). aDescriptor addMapping: (DirectMapping from: #name to: (table fieldNamed: 'NAME')). (self typeResolverFor: AcademiaPublication) register: aDescriptor keyedBy: 'AcademiaPublication' field: (table fieldNamed: 'CLASSTYPE'). ^self AcademiaTestsDescriptor>>tableForACADEMIAPUBLICATION: aTable (aTable createFieldNamed: 'ID' type: platform serial) bePrimaryKey. aTable createFieldNamed: 'NAME' type: (platform varChar: 255). aTable createFieldNamed: 'CLASSTYPE' type: (platform varChar: 40). aTable createFieldNamed: 'CONTENT' type: (platform varChar: 255). aTable createFieldNamed: 'VENUE' type: (platform varChar: 255). aTable createFieldNamed: 'ISSHORT' type: platform boolean. aTable createFieldNamed: 'CHAPTERNUMBER' type: platform real. ^self ================ When I try this simple test: ===code snippet=== testInheritance | bookChapters conferencePapers publications | bookChapters := Array with: self bookChapter1 with: self bookChapter2. conferencePapers := Array with: self conferencePaper1 with: self conferencePaper2. publications := Core.OrderedCollection new. publications addAll: conferencePapers. publications addAll: bookChapters. publications add: self genericPublication. dbBridge storeObjectOnDB: publications. dbBridge disconnect. dbBridge connect. dbBridge readManyOf: AcademiaPublication. ================ I get an error when the ElementBuilder tries to populate the instance. It complains that it does not find the key for the field ACADEMIAPUBLICATION.CHAPTERNUMBER: This is the stack report: ===stack snippet=== Key not found: IdentityDictionary(Dictionary)>>keyNotFoundErrorFor:index: optimized [] in Dictionary>>at: IdentityDictionary>>at:ifAbsent: IdentityDictionary(Dictionary)>>at: Glorp.ObjectBuilder(Glorp.ElementBuilder)>>translateFieldPosition: Glorp.ObjectBuilder(Glorp.ElementBuilder)>>valueOfField: Glorp.DirectMapping>>valueInBuilder:as: Glorp.DirectMapping>>valueInBuilder: Glorp.DirectMapping>>mapObject:inElementBuilder: optimized [] in Glorp.Descriptor>>populateObject:inBuilder: Array(SequenceableCollection)>>do: Glorp.Descriptor>>populateObject:inBuilder: Glorp.ObjectBuilder>>populateInstance Glorp.ObjectBuilder>>buildObjectFrom: optimized [] in Glorp.GlorpCursoredStream>>buildObjectsForRow: Array(SequenceableCollection)>>do: Glorp.GlorpCursoredStream>>buildObjectsForRow: Glorp.GlorpCursoredStream>>nextAnswerFromUnderlyingCursor Glorp.GlorpCursoredStream>>nextAnswer Glorp.GlorpCursoredStream>>next Glorp.GlorpCursoredStream>>upToEnd Glorp.SimpleQuery(Glorp.Query)>>resultCollectionFor: Glorp.SimpleQuery(Glorp.AbstractReadQuery)>>readFromDatabaseWithParameters: Glorp.SimpleQuery(Glorp.AbstractReadQuery)>>executeWithParameters:in: MetaDB.EvoDBSession(Glorp.GlorpSession)>>execute: MetaDB.EvoDBSession(Glorp.GlorpSession)>>readManyOf: MetaDB.MetaDBBridge>>readManyOf: MetaDB.AcademiaTests>>testInheritance ================ I spent the whole afternoon trying to figure out the cause of the problem. When I use the GlorpTests, they work perfectly. For example I tried GlorpFilteredInheritanceTest, and it has no problem. In fact, the ElementBuilder in that case (which is for Glorp.Employee) has all the fields that are necessary also for the subclasses. In my case, the ElementBuilder has only the fields of the superclass. Unfortunately, I cannot understand why. If in the subclasses I use only instance variables and fields that are in the superclass (e.g., by removing chapterNumber), then the test works and I got a collection of AcademiaPublication, which is formed by the correct subclasses. Could you help me? I would really appreciate some hints... Thank you in advance, Alberto _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Give us a much smaller example where it does not work.
|
Free forum by Nabble | Edit this page |