Announcement Announcement Module
Collapse
No announcement yet.
StaleObject Exception Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • StaleObject Exception

    Hi all

    I am using Spring and Hiernate to access an Oracle database. I have my service under Spring.
    the following is the structure and I made sure that I am not getting the error from the interceptor. It is throwing from the check() method from the abstractDAyaAccessXXXXX class. If you see my code you can see that I do make some database calls to make some validations before saving. If I comment out my validations, this code is working fine. I have single session set to "true" in the web.xml. Any ideas Gurus?????


    From My action

    MyService.SAveMyData(DTO)

    MyService
    public Collection saveMyData(Dto dto){
    Collections errors = validateme(dto);

    if(!errors.isEmpty){
    return errors;
    }

    saveMyGoodData(dto);
    return null;
    }

    public Collection validateMe(dto){
    // call some name querries to access table InnerPojo and do some validations
    // Do my validations here
    return errors;
    }
    public void saveMyGoodData(Dt dto){

    BaPojo ba = (BaPojo )getTemplate().findbyPrimaryKey(BaPojo.class,dto.g etKey());
    InnerPojo inPojo = ba.getInnerPojo();
    //set values to innerPojo
    getTemplate().saveOrUpdate(inPojo );
    ba.setInnerPojo(inPojo );
    getTemplate().saveOrUpdate(ba);
    }

  • #2
    Most likely you are modifing the objects your are trying to save during your validation. Probably doing the queries you associate your object with the current session and at some point change a value which forces a save.
    getTemplate probably uses a different session or just tries to save the old version of the object which is not attached and which causes the exception.
    Turn on logging on both hibernate and Spring and you'll see the workflow of the objects and sessions.

    Comment

    Working...
    X