Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Behaviour of changed data read by ClientSession
Behaviour of changed data read by ClientSession [message #1795722] Thu, 27 September 2018 09:40
thorsten kruse is currently offline thorsten kruseFriend
Messages: 6
Registered: October 2017
Junior Member
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,
Previous Topic:@NamedStoredProcedureQueries with Spring Jpa
Next Topic:Toplink to Eclipselink migration
Goto Forum:

Current Time: Tue May 21 07:19:39 GMT 2024

Powered by FUDForum. Page generated in 0.02640 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top