Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Expression for all lineitems that where picked today

The function addDate() takes a date as argument, not the expression builder. 
minimum() is an aggregation function, so can only be used in the SELECT
clause.  You must set the selectionCriteria to the resulting Expression not
the expression builder.

Try something like,

final ExpressionBuilder eb = new ExpressionBuilder();
Expression expression =
eb.get("pickedAt").greaterThanEqual(eb.today().addDate("day",
0)).and(eb.lessThan(eb.today().addDate("day", 1)));
ReadAllQuery query = new ReadAllQuery(LegacyOrderPosition.class);
query.setSelectionCriteria(expression);
query.addAscendingOrder("pickedAt");
query.setMaxRows(1);
final Object first = JpaHelper.createQuery(query,
em).getResultList().get(0);

Or use a sub select,

ExpressionBuilder subBuilder = new ExpressionBuilder();
Expression subExpression =
subBuilder.get("pickedAt").greaterThanEqual(subBuilder.today().addDate("day",
0)).and(subBuilder.lessThan(subBuilder.today().addDate("day", 1)));
ReportQuery subQuery = new ReportQuery(LegacyOrderPosition.class);
subQuery.setSelectionCriteria(expression);
subQuery.addMinimum("pickedAt");

ReadObjectQuery query = new ReadObjectQuery(LegacyOrderPosition.class);
ExpressionBuilder eb= new ExpressionBuilder();
query.setSelectionCriteria(eb.get("pickedAt").equal(subQuery));

Object first = JpaHelper.createQuery(query, em).getSingleResult();


philk wrote:
> 
> Hello,
> 
> I am struggling constructing my EL expression for the following:
> "Select the first lineitem that was picked today"
> 
> final ExpressionBuilder eb = new ExpressionBuilder();
> eb.get("pickedAt").greaterThanEqual(eb.addDate("day",
> 0)).and(eb.lessThan(eb.addDate("day", 1)))
>                         .minimum();
> ReadObjectQuery query = new ReadObjectQuery(LegacyOrderPosition.class);
> query.setSelectionCriteria(eb);
> final Object first = JpaHelper.createQuery(query, em).getSingleResult();
> 
> But this will not return me the expected entity, but rather some random
> entity that does not even have the "pickedAt" member set (its null).
> 
> How would I compose that query and how could I use the database provided
> DATE() method rather than the to give the date from the client using "new
> Date()".
> 
> Regards,
> Phil
> 
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
> 
> 


-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
-- 
View this message in context: http://www.nabble.com/Expression-for-all-lineitems-that-where-picked-today-tp24253618p24275092.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top