Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Expressions query generated property but execution returns no results when they
Expressions query generated property but execution returns no results when they [message #389404] Thu, 04 June 2009 05:36 Go to next message
Rahul Thakur is currently offline Rahul Thakur
Messages: 40
Registered: July 2009
Member
Greetings,

I am using Expressions framework to dynamically build queries. However, I
notice from logs that though the query generated is valid (returns
expected results when I run it from DB console), it does not return any
results when run via JPA.

There are no errors on anything and I am wondering if there is anything
else I can try to investigate this further.

Here's the snippet:
ReadObjectQuery query = new ReadObjectQuery(Project.class);
query.setFirstResult(0);
query.setMaxRows(100);
ExpressionBuilder project = query.getExpressionBuilder();
Expression exp = null;

if (null != this.projectNameNumber
&& !this.projectNameNumber.trim().equals("")) {
exp = project.get("name").like("%" + this.projectNameNumber +
"%").or(project.get("code").like("%" + this.projectNameNumber + "%"));
}

if (null != this.workOrderNumber &&
!this.workOrderNumber.trim().equals("")) {
Expression subExp = project.anyOf("workOrders").get("code")
.like("%" + this.workOrderNumber + "%");
if (null == exp)
exp = subExp;
else
exp = exp.and(subExp);
}

if (null != this.projectStartDate) {
Expression subExp =
project.get("startDate").greaterThan(this.projectStartDate);
if (null == exp)
exp = subExp;
else
exp = exp.and(subExp);
}

List<Project> results = store.queryByExample(Project.class, 0, 10, exp);
// Zero size list obtained!

Here's the generated query :
SELECT DISTINCT t0.ID, t0.OBJ_VERSION, t0.START_DATE, t0.END_DATE,
t0.PROJECT_CODE, t0.DATE_UPDATED, t0.FLG_IS_ACTIVE,
t0.PROJECT_DESCRIPTION, t0.PROJECT_NAME, t0.DATE_CREATED,
t0.ID_CLIENT_USER, t0.ID_COMPANY FROM PROJECT t0, WORK_ORDER t1 WHERE
(((((t0.PROJECT_NAME LIKE ?) OR (t0.PROJECT_CODE LIKE ?)) AND
(t1.WORK_ORDER_CODE LIKE ?)) AND (t0.START_DATE > ?)) AND (t1.ID_PROJECT =
t0.ID))
bind => [%GEN%, %GEN%, %M7%, 2009-12-12]


Look forward to hear...

Many thanks,

Rahul
Re: Expressions query generated property but execution returns no results when they [message #389416 is a reply to message #389404] Tue, 09 June 2009 09:38 Go to previous message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

That is very odd. Check that you are connecting to the same database, and
that the data is committed and that you are not clearing the data. If you
just try a ReadAllQuery or a simpler selection criteria do you get the
expected results?

Also include what your queryByExample method does.

It may be an issue with your bind parameters, ensure they are of the
correct type.

---
James
http://www.nabble.com/EclipseLink---Users-f26658.html


James : Wiki : Book : Blog : Twitter
Previous Topic:Help with error: number of referencing and referenced column
Next Topic:EclipseLink weaver agent or Spring agent
Goto Forum:
  


Current Time: Thu Apr 17 14:33:48 EDT 2014

Powered by FUDForum. Page generated in 0.02022 seconds