Simple one to many mapping not working

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

Simple one to many mapping not working

Esteban A. Maringolo
I'm testing GLORP with the most simple example from a guide I found online.

But I can't make it work, which is really really frustrating.

As a test scenario, I want to map two classes, a StoreChain (e.g. Wal-Mart, HEB, etc) and Stores.
Each StoreChain has a list of Stores, and the Store knows back to which chain it belongs.

This simple example doesn't work, it creates both the Store and the StoreChain.

session inUnitOfWorkDo: [ 
| chain |
chain := StoreChain newNamed: 'Wal-Mart'.
chain addStore: (Store newNamed: 'Wal-Mart #13203'). "#addStore: sets receiver's as store's #chain ."
session register: chain.
].

I get a "DBXRecoverableError: RECOVERABLE OpenDBX: ERROR:  null value in column "id" violates not-null constraint DETAIL:  Failing row contains (null, Wal-Mart).

It seems it's not initializing the ID, but the sequence is there.

If I split the procedure in two:
session inUnitOfWorkDo: [ session register: (StoreChain newNamed: 'Wal-Mart')]. "This works"

session inUnitOfWorkDo: [ 
| chain store |
chain := session readOneOf: GptStoreChain where: [ :each | each name = 'Wal-Mart' ].
chain addStore: (GptStore newNamed: 'Wal-Mart Test').
]. "Fails"

It fails with: MessageNotUnderstood: StoreChain>>asNumber
Sent by PostgresSQLPlatform>>#convertToInteger:for:

Any hints?


In my DescriptorSystem I have:

useDirectAccessForMapping
^false

tableForSTORE_CHAIN: aTable
(aTable createFieldNamed: 'id' type: platform sequence) bePrimaryKey.
(aTable createFieldNamed: 'name' type: (platform varChar: 100)).

tableForSTORE: aTable
| chainId |
(aTable createFieldNamed: 'id' type: platform sequence) bePrimaryKey.
(aTable createFieldNamed: 'name' type: (platform varChar: 100)).
chainId := (aTable createFieldNamed: 'store_chain_id' type: platform integer) .
      aTable addForeignKeyFrom: chainId to: ((self tableNamed: 'STORE_CHAIN') fieldNamed: 'id')


descriptorForStore: aDescriptor
| table |
table := self tableNamed: 'STORE'.
aDescriptor table: table.
(aDescriptor newMapping: DirectMapping) from: #id to: (table fieldNamed: 'id').
(aDescriptor newMapping: DirectMapping) from: #name to: (table fieldNamed: 'name').
(aDescriptor newMapping: DirectMapping) from: #chain to: (table fieldNamed: 'store_chain_id')

descriptorForStoreChain: aDescriptor
| table |
table := self tableNamed: 'STORE_CHAIN'.
aDescriptor table: table.
(aDescriptor newMapping: DirectMapping) from: #id to: (table fieldNamed: 'id').
(aDescriptor newMapping: DirectMapping) from: #name to: (table fieldNamed: 'name').
(aDescriptor newMapping: ToManyMapping) attributeName: #stores.


classModelForStoreChain: aClassModel
aClassModel newAttributeNamed: #id.
aClassModel newAttributeNamed: #name.
aClassModel newAttributeNamed: #stores collectionOf: Store

classModelForStore: aClassModel
aClassModel newAttributeNamed: #id.
aClassModel newAttributeNamed: #name.
aClassModel newAttributeNamed: #chain type: StoreChain



--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/glorp-group.
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: Simple one to many mapping not working

Esteban A. Maringolo
I made it work.
The problem was in the descriptors.

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/glorp-group.
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: Simple one to many mapping not working

Alan Knight
Right. The problem was that chain is a StoreChain, not an integer, so you want a OneToOneMapping for it, not a DirectMapping, right?

On Monday, September 23, 2013 5:37:08 AM UTC-7, Esteban A. Maringolo wrote:
I made it work.
The problem was in the descriptors.

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/glorp-group.
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: Simple one to many mapping not working

Esteban A. Maringolo
Yeap, it was that. Thank you.



El lunes, 23 de septiembre de 2013 18:24:28 UTC-3, alan.knight escribió:
Right. The problem was that chain is a StoreChain, not an integer, so you want a OneToOneMapping for it, not a DirectMapping, right?

On Monday, September 23, 2013 5:37:08 AM UTC-7, Esteban A. Maringolo wrote:
I made it work.
The problem was in the descriptors.

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/glorp-group.
For more options, visit https://groups.google.com/groups/opt_out.