Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » I must be missing something!
I must be missing something! [message #383029] Mon, 17 November 2008 13:45 Go to next message
testit is currently offline testit
Messages: 1
Registered: July 2009
Junior Member
This always returns all of the rows in the table. There are only a couple
of rows where departmentId is equal to 1.

What did I miss?

public List<Employee> getEmployees( Employee criteria, int page,
int limit ) throws Exception
{
ReadAllQuery query = new ReadAllQuery(Employee.class);
ExpressionBuilder eb = query.getExpressionBuilder();
eb.get("departmentId").equal( 1 );
query.setSelectionCriteria(eb);
query.refreshIdentityMapResult();
List employees = (List) session.executeQuery(query);
return employees;
}
Re: I must be missing something! [message #383033 is a reply to message #383029] Tue, 18 November 2008 08:25 Go to previous message
Doug Clarke is currently offline Doug Clarke
Messages: 155
Registered: July 2009
Senior Member
The line:

eb.get("departmentId").equal( 1 );

creates an expression object that you need to set into the selection
criteria. The ExpressionBuilder is a factory for these expressions. If you
re-write your code as:



> public List<Employee> getEmployees( Employee criteria, int page,
> int limit ) throws Exception
> {
> ReadAllQuery query = new ReadAllQuery(Employee.class);
> ExpressionBuilder eb = query.getExpressionBuilder();
> Expression exp = eb.get("departmentId").equal( 1 );
> query.setSelectionCriteria(exp);
> query.refreshIdentityMapResult();
> List employees = (List) session.executeQuery(query);
> return employees;
> }

It should work for you.

Doug
Previous Topic:EJBQL translaltion problem
Next Topic:PostLoad on a new instance?
Goto Forum:
  


Current Time: Thu Aug 28 01:32:27 EDT 2014

Powered by FUDForum. Page generated in 0.10799 seconds