Results 1 to 2 of 2

Thread: StaleObject Exception

  1. #1
    Join Date
    Feb 2006
    Posts
    1

    Default 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. #2
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    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.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •