Expressions query generated property but execution returns no results when they [message #389404] |
Thu, 04 June 2009 09:36 |
Rahul Thakur Messages: 39 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.02917 seconds