My guess is that you have SaveAutomatic="false" on the one-to-one associations and you are not explicity saving object a.
When you call OtherObjectB.find(b) it processes the one-to-one association to load the a object. Because a is in the cache object b will reference the cached copy of A. Since you didn't save A, the cache hasn't been updated and the A object (in the cache) will still be in it's initial state.
Clearing the cache forces the retrieve to disk, and since obj B has a reference to A in the table, the a will load with all 10 b objects.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have a following structure:
A oneToMany B and B oneToOne A.
Class A has a collection of B ("Items")
a.items.count ' debug (9)
now
a.items.add(otherObjectB)
a.items.count 'debug (10)
now
otherObjectB.a.items.count ' Debug 10
...
commit of transaction
it is correct, but
if I execute
OtherObjectB.find(b)
OtherObjectB.items.count ' Debug is 9 and not 10
what happen, I think that in the cache exist 2 object OtherObjectB
if i execute clear cache, then it is correct and i have 10
My guess is that you have SaveAutomatic="false" on the one-to-one associations and you are not explicity saving object a.
When you call OtherObjectB.find(b) it processes the one-to-one association to load the a object. Because a is in the cache object b will reference the cached copy of A. Since you didn't save A, the cache hasn't been updated and the A object (in the cache) will still be in it's initial state.
Clearing the cache forces the retrieve to disk, and since obj B has a reference to A in the table, the a will load with all 10 b objects.