Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Behaviour of changed data read by ClientSession

Hello all,

I have a singelton ServerSession from which I get ClientSession instances and I have an Employee entity. Have a look at following code sequence and the comments:

        //Query for employee Bob
        ExpressionBuilder eb = new ExpressionBuilder();
        _expression_ exp = eb.get("name").equal("Bob");
        ReadAllQuery raq = new ReadAllQuery(Employee.class);

        //ClientSession A
        Session csA = DBSessionProvider.getInstance().getNewClientSession();
        Vector<Employee> resultSetEmployeeCsA = (Vector<Employee>) csA.executeQuery(raq); //ask for Bob

        System.out.println(resultSetEmployeeCsA.size()); //out: 1
        Employee empBobA = resultSetEmployeeCsA.firstElement();
        System.out.println(; //out: Bob = "Jake";
        System.out.println(; //out: Jake

        //ClientSession B
        Session csB = DBSessionProvider.getInstance().getNewClientSession();
        Vector<Employee> resultSetEmployeeCsB = (Vector<Employee>) csB.executeQuery(raq); //ask for Bob!
        System.out.println(resultSetEmployeeCsB.size()); //out: 1, expected 0
        if (!resultSetEmployeeCsB.isEmpty())
            Employee empBobB = resultSetEmployeeCsB.firstElement();
            System.out.println(; //out: Jake but asked for Bob (?!?)

        //Query for Employee Jake
        ExpressionBuilder ebJ = new ExpressionBuilder();
        _expression_ expJ = ebJ.get("name").equal("Jake");
        ReadAllQuery raqJ = new ReadAllQuery(Employee.class);
        //ClientSession C
        Session csC = DBSessionProvider.getInstance().getNewClientSession();
        Vector<Employee> resultSetEmployeeCsC = (Vector<Employee>) csC.executeQuery(raqJ); //ask for Jake
        System.out.println(resultSetEmployeeCsC.size()); //out: 0, expected 1

        UnitOfWork uow = DBSessionProvider.getInstance().getNewClientSession().acquireUnitOfWork();
        Vector<Employee> resultSetUOW = (Vector<Employee>) uow.executeQuery(raq); //ask for Bob!
        System.out.println(resultSetUOW.size()); //out: 1, expected 0
        if (!resultSetUOW.isEmpty()) //expected empty resultSet!
            Employee empBobUOW = resultSetUOW.firstElement();
            System.out.println(; //out: Jake but asked for Bob (?!?)
        //nothing commited, calculateChanges(): = Jake ==
        //Logically, but looks strange: differs from DB and is not commited

To my mind you are able to manipulate ServerSession entities (read by ClientSession) and the manipulated entities are the base for following Sessions. I expect, a new created Session has to contain the indeed state of the Entities (from DB?) and not an uncommitet state from another Session.

Do I get the concept of Sessions wrong? Is the way I discribed in my code possible but bad practice, so I have to keep attention not to do so?

Thanks for hints and comments,

Back to the top