0

A Parent entity object that have some child and it's child maybe change the parent object status , for preventing from concurrency problem there is a nice solution that the name Is : Optimistic Lock

and this nice article from Vlad Mihalcea blog solve all the major problem and you dont need worry about the manage version field from parent and child action for increase the version .

but the problem is here : my object that you can imagine that as a parent object depend to about 4 child object , and the some of these child object do their actions form a procedure in database side . Does it logical doing the update operation for version field in database side ? or it's not how can i solve the problem ? what's the solution ?

some of my code example is here :

@Transactional
    public Long save(Long entityId) {
                 Parent parent= iParentService.loadByEntityId(entityId);
                 parent.setStatus(0)// known as first regstration
                 iParentService.persist(parent);
    }

in the child save operation in application side maybe change and update occure on parent :

   @Transactional
            public Long save(Long childId) {
                         Child child= iChildService.loadByEntityId(childId);
                         Parent parent = child.getParent(); 
                         parent.setStatus(1)// save complete 
                         iParentService.persist(parent);
                         iChildService.persist(child);
            }

and the confirm operation in database side is in the Oracle procedure and call it from application data access layer like this :

 Query query = session.createSQLQuery("{call    DBPK_PARENT.CONFIRM(:parentId,:userId,:userIp)} ");
    query.setParameter("parentId", parentId);
    query.setParameter("userId", userId);
    query.setParameter("userIp", userIp);
    query.executeUpdate();

and in the end of it run a sql command that update parent entity status lie this :

update Parent p 
set p.status=2 -- known as confirm status 
where p.id=parentId;
Mohammad Mirzaeyan
  • 845
  • 3
  • 11
  • 30

0 Answers0