cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Lindesay <>
Subject Re: Expressions involving dates can't be converted to EJBQL?
Date Wed, 12 Aug 2015 09:20:56 GMT
Hi Hugi;

You can use EJBQL queries with timestamps, but there is presently no 
supported _literal_ representation for a timestamp inside the query 
string so you have to use parameters instead.  Here is an example;

   EJBQLQuery q = new EJBQLQuery(String.format(
     "DELETE FROM %s r WHERE r.createTimestamp < :expiryTimestamp",

     new Timestamp(System.currentTimeMillis() -


To help with getting Expression objects to over to EJBQL with timestamp 

   Expression#toEJBQL(List<Object> parameterAccumulator, String rootId)

So you call that and as it creates the EJBQL fragment, it will insert 
any necessary parameters into the parameterAccumulator for you all set 
to go into the EJBQLQuery.

Hopefully that helps?



   For example;

   SELECT f FROM Foo f WHERE f.createTimestamp > ?

Then you just need to use the

On 12/08/15 20:35, Hugi Thordarson wrote:
> Hi Andrew,
> thanks for that. I see what the problem is.
> But if I can’t use EJBQL when generating queries that use dates, can I go down any
different paths or do I have to revert to writing plain old SQL?

Andrew Lindesay

View raw message