I have Parent-Child relationship.
The relationship is such that Parent can have a set of child and a Child can have of set parents.
At one point, a child C1 from parent P1 is removed and is assigned to another parent P2.
What I was doing was :
Parent p1 = myDao.getParent(p1_oid);
Child c1 = p1.getChild(child_oid);
p1.removeChild(c1);
Parent p2 = myDao.getParent(p2_oid);
p2.addChild(c1);
myDao.merge(p1);
myDao.merge(p2);
This piece of code was updating my database table properly. But in my code when I am retrieving the set of child using myDao.getAllChild() the parent for C1 is still P1 not P2.
timeToLiveSeconds for the cache region is 600 and I can see that exactly after 10 mins(600 seconds) if i retrieve the set of child, the parent is updated properly, i.e., parent of c1 is now p2.
My question here is why was the cache not updated when I did the merge()?
I changed my above piece of code a bit to :
Parent p1 = myDao.getParent(p1_oid);
Child c1 = p1.getChild(child_oid);
p1.removeChild(c1);
Parent p2 = myDao.getParent(p2_oid);
//added this line.
c1.addParent(p2);
p2.addChild(c1);
myDao.merge(p1);
myDao.merge(p2);
Now when I am doing myDao.getAllChild() I am able to get updated set of child.(i.e., with parent of C1 as P2)
Can some one tell me what is happening here?