Registration of basic objects after retrieve:

3 views
Skip to first unread message

Esteban Maringolo

unread,
Nov 23, 2020, 5:27:16 PM11/23/20
to GLORP Mailing List
Hi,

I was getting some issues with objects lazily initialized that forced
a read during the commit phase, triggering an exception.

Since I couldn't fix that, I did a little modification of the
architecture to delegate that lazily initialized collection to another
component, and then the issue happened again, to simplify it and make
it even faster, I performed a simple retrieve to fetch just one value
from the DB.

E.g.
query := SimpleQuery
readOneOf: GwPlayerHandicap
where: [ :each | each player = aGwPlayer AND: [ each date <= aDate ] ].
query orderBy: [ :each | each date descending ].
query retrieve: [ :each | each value ].

The weird thing is that when retrieve that single value (an Integer in
this case) it attempts to register in vía `privateRegisterAsOld:
anObject`, which IMO is meaningless, since such an object won't be
mapped to the database in any way.

GlorpSession>>privateRegisterAsOld: anObject
"Register the object as something we already read from the database,
skipping the isNew: test. Private! Normally you would just use
register:"
| realObject |
currentUnitOfWork isNil ifTrue: [^self].
realObject := self realObjectFor: anObject ifNone: [^self].
currentUnitOfWork register: realObject

I added a break condition before that, in this case for two simple
value objects and this solved the issue:

GlorpSession>>privateRegisterAsOld: anObject
| realObject |
currentUnitOfWork isNil ifTrue: [^self].
realObject := self realObjectFor: anObject ifNone: [^self].
(realObject isString or: [ realObject isNumber ]) ifTrue: [ ^self ].
currentUnitOfWork register: realObject

Am I missing something here?

Esteban A. Maringolo

Alan Knight

unread,
Nov 23, 2020, 9:03:51 PM11/23/20
to glorp...@googlegroups.com
I think the right test is that if the object doesn't have a descriptor you skip it. But I'd kind of expect register to do that anyway.

Also with the initial issue, you might be able to map the field or otherwise bypass the lazy initialization so the first issue doesn't happen.

--
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 glorp-group...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/CAJMgPCKpg3OGZuwU84kTnOJc2b75C8HgESvb7H_E0U2cNW5q2Q%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages