[vwnc] VW7.6 Glorp 7.7-60 Bug (?) with Mapping hierarchy to different tables and ToManyMapping

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
vam
Reply | Threaded
Open this post in threaded view
|

[vwnc] VW7.6 Glorp 7.7-60 Bug (?) with Mapping hierarchy to different tables and ToManyMapping

vam
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] VW7.6 Glorp 7.7-60 Bug (?) with Mapping hierarchy to different tables and ToManyMapping

Michael Lucas-Smith-2
VAM wrote:

> I have next situation
> 1. Hierarchy of classes
> Abstract class Media and subclasses: Book, Disk
>
> If I use simple mapping there classes with mapping  Books and Disks into
> different tables, then all works fine.
>
> Next step, I introduced new class - Library.
> Library contents collection of Book or Disk.
> And when I save Library into DB I get error: ''
> If turn on DatabaseAccessor logging we see, that Glorp not mapping libraryId
> for Book (or Disk).
>  
For this to work the way you've specified it, glorp would need to do N
queries (depending on how many type resolvers there are) or N joins.
Alternatively, you can have a second column on the library table that
knows which type the id is meant to be. I don't know the exact code to
do this, but you might want to join the new glorp mailing list and ask
there.

Michael
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] VW7.6 Glorp 7.7-60 Bug (?) with Mapping hierarchy to different tables and ToManyMapping

Alan Knight-2
In reply to this post by vam
I think the issue here is that if you want to define the relationship from Library to Books|Disks that you'll need to define a complex join on that relationship. Glorp isn't smart enough to figure that one out on its own. See descriptorForGlorpWarehouse: in the Glorp test code. However, I think if you defined the reverse relationships from Book->Library and Disk->Library that that might be adequate.

At 06:11 PM 4/13/2009, VAM wrote:

I have next situation
1. Hierarchy of classes
Abstract class Media and subclasses: Book, Disk

If I use simple mapping there classes with mapping  Books and Disks into
different tables, then all works fine.

Next step, I introduced new class - Library.
Library contents collection of Book or Disk.
And when I save Library into DB I get error: ''
If turn on DatabaseAccessor logging we see, that Glorp not mapping libraryId
for Book (or Disk).

DescriptorSystem>>descriptorForBook: aDescriptor
        | table |
        table := self tableNamed: 'BOOKS'.
         aDescriptor table: table.
         aDescriptor directMappingFor: #id.
         aDescriptor directMappingFor: #title.
         aDescriptor directMappingFor: #pageCount.
        (self typeResolverFor: Media) register: aDescriptor


DescriptorSystem>>descriptorForDisk: aDescriptor
        | table |
        table := self tableNamed: 'DISKS'.
         aDescriptor table: table.
         aDescriptor directMappingFor: #id.
         aDescriptor directMappingFor: #title.
         aDescriptor directMappingFor: #trackCount.
        (self typeResolverFor: Media) register: aDescriptor

DescriptorSystem>>descriptorForLibrary: aDescriptor
        | table |
        table := self tableNamed: 'LIBRARY'.
         aDescriptor table: table.
         aDescriptor directMappingFor: #id.
         aDescriptor addMapping:
                          ((ToManyMapping new)
                                   attributeName: #items;
                                   referenceClass: Media;
                                   beExclusive)

DescriptorSystem>>descriptorForMedia: aDescriptor
        (self typeResolverFor: Media) register: aDescriptor abstract: true

DescriptorSystem>>tableForBOOKS: aTable
        (aTable createFieldNamed: 'id' type: (platform varchar: 100)) bePrimaryKey.
        (aTable createFieldNamed: 'libraryId' type: (platform varchar: 100))
beNullable: false.
        (aTable createFieldNamed: 'title' type: (platform varchar: 256))
beNullable: false.
        (aTable createFieldNamed: 'pageCount' type: platform int) beNullable:
false.

        aTable addForeignKeyFrom: (aTable fieldNamed: 'libraryId') to: ((self
tableNamed: 'LIBRARY') fieldNamed: 'id')

DescriptorSystem>>tableForDISKS: aTable
        (aTable createFieldNamed: 'id' type: (platform varchar: 100)) bePrimaryKey.
        (aTable createFieldNamed: 'libraryId' type: (platform varchar: 100))
beNullable: false.
        (aTable createFieldNamed: 'title' type: (platform varchar: 256))
beNullable: false.
        (aTable createFieldNamed: 'trackCount' type: platform int) beNullable:
false.

        aTable addForeignKeyFrom: (aTable fieldNamed: 'libraryId') to: ((self
tableNamed: 'LIBRARY') fieldNamed: 'id')

DescriptorSystem>>tableForLIBRARY: aTable
        (aTable createFieldNamed: 'id' type: (platform varchar: 100)) bePrimaryKey

DescriptorSystem>>typeResolverForMedia
         ^HorizontalTypeResolver forRootClass: Media

--
View this message in context: http://www.nabble.com/-vwnc--VW7.6-Glorp-7.7-60-Bug-%28-%29-with-Mapping-hierarchy-to-different-tables-and-ToManyMapping-tp23027667p23027667.html
Sent from the VisualWorks mailing list archive at Nabble.com.

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc

--
Alan Knight [|], Engineering Manager, Cincom Smalltalk

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc