Behaviour of changed data read by ClientSession

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Behaviour of changed data read by ClientSession

Thorsten Kruse
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);
        raq.setSelectionCriteria(exp);

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

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

        empBobA.name = "Jake";
        System.out.println(empBobA.name); //out: Jake

        //ClientSession B
        Session csB = DBSessionProvider.getInstance().getNewClientSession();
        Vector<Employee> resultSetEmployeeCsB = (Vector<Employee>) csB.executeQuery(raq); //ask for Bob!
        csB.release();
        System.out.println(resultSetEmployeeCsB.size()); //out: 1, expected 0
        if (!resultSetEmployeeCsB.isEmpty())
        {
            Employee empBobB = resultSetEmployeeCsB.firstElement();
            System.out.println(empBobB.name); //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);
        raqJ.setSelectionCriteria(expJ);
        //ClientSession C
        Session csC = DBSessionProvider.getInstance().getNewClientSession();
        Vector<Employee> resultSetEmployeeCsC = (Vector<Employee>) csC.executeQuery(raqJ); //ask for Jake
        csC.release();
        System.out.println(resultSetEmployeeCsC.size()); //out: 0, expected 1


        //UnitOfWork
        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(empBobUOW.name); //out: Jake but asked for Bob (?!?)
        }
        uow.commit();
        //nothing commited, calculateChanges(): employee.name = Jake == empBobUOW.name
        //Logically, but looks strange: employee.name 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,
Thorsten

_______________________________________________
eclipselink-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/eclipselink-users