I'm trying to filter on a DateTimeOffset (myDate in the examples below). Since I want to ignore the time part, I believe the only way to filter is to compare separately the year, month and day components e.g.

...entities?$filter=year(myDate) eq 2013

This is also in accordance with the ODATA spec: http://www.odata.org/documentation/odata-v3-documentation/url-conventions/#512412_year

The problem is... it just does not work:

Caused by: java.lang.UnsupportedOperationException: unsupported expression YearMethodCallExpression
 
at org.odata4j.producer.jpa.JPQLGenerator.toJpql(JPQLGenerator.java:187)
at org.odata4j.producer.jpa.JPQLGenerator.binaryCommonExpressionToJpql(JPQLGenerator.java:309)
at org.odata4j.producer.jpa.JPQLGenerator.toJpql(JPQLGenerator.java:192)
at org.odata4j.producer.jpa.GenerateJPQLCommand.generateJPQL(GenerateJPQLCommand.java:121)&#xd  ;
at org.odata4j.producer.jpa.GenerateJPQLCommand.execute(GenerateJPQLCommand.java:34)
at org.odata4j.producer.jpa.Chain.execute(Chain.java:29)
at org.odata4j.producer.jpa.JPAProducer.getEntities(JPAProducer.java:278)

If I use the filter below then I don't get any error, but it's not what I want to do because the time part in myDate is never midnight (T00:00:00.000Z) so the equality always results in a False:

...entities?$filter=myDate eq datetimeoffset'2013-09-30T00:00:00.000Z'

Any idea? Many thanks!

有帮助吗?

解决方案

A workaround for this issue is to use the following two filters:

...entities?$filter=myDate ge datetimeoffset'2013-09-30T00:00:00.000Z' and myDate lt datetimeoffset'2013-10-30T00:00:00.000Z'

I still don't understand why the year/month/day functions don't work though.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top