<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Java/Hibernate odata filter by datetime is not working in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/java-hibernate-odata-filter-by-datetime-is-not-working/qaa-p/744168#M210380</link>
    <description>&lt;P&gt;Hi Ivan,&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;Please check the following tutorial on how to setup Hibernate for HANA in Eclipse. I think it might help you checking your project setup. &lt;/P&gt;
  &lt;P&gt;More specifically, check the following attribute on your hibernate persistence config:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;hibernate.dialect=org.hibernate.dialect.HANAColumnStoreDialect&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;The "unexpected char" tells me that hibernate is generating invalid SQL commands to your HANA DB (I am assuming you are trying to run your JPA project against a HABA DB. Am I correct?).&lt;/P&gt;
  &lt;P&gt;While checking the SQL command from the provided error I've noticed the usage of function 'ts'. This shows that hibernate isn't generating HANA compatible SQL code, as there is no such &lt;A href="https://help.sap.com/viewer/4fe29514fd584807ac9f2a04f6754767/2.0.01/en-US/209ddefe75191014ac249bf78ba2a1e9.html" target="_blank"&gt;data type conversion function&lt;/A&gt; on HANA. The closest SQL function that is perhaps equivalent to a time stamp conversion function taking as input a formatted string would be the &lt;A href="https://help.sap.com/viewer/4fe29514fd584807ac9f2a04f6754767/2.0.01/en-US/20f1a5b075191014b773acf0dc277cae.html" target="_blank"&gt;TO_TIMESTAMP.&lt;/A&gt; &lt;/P&gt;
  &lt;P&gt;I think that by setting the correct dialect, the generated SQL syntax will be correct.&lt;/P&gt;
  &lt;P&gt;I would also try running the same SQL commands seen on your Hibernate application against your DB via SQL Console. That way you will be able to figure out which part of the SQL command is wrong. &lt;/P&gt;
  &lt;P&gt;Best regards,&lt;BR /&gt;Ivan&lt;/P&gt;</description>
    <pubDate>Mon, 13 Aug 2018 14:04:33 GMT</pubDate>
    <dc:creator>Ivan-Mirisola</dc:creator>
    <dc:date>2018-08-13T14:04:33Z</dc:date>
    <item>
      <title>Java/Hibernate odata filter by datetime is not working</title>
      <link>https://community.sap.com/t5/technology-q-a/java-hibernate-odata-filter-by-datetime-is-not-working/qaq-p/744165</link>
      <description>&lt;P&gt;Hi Experts!&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;In my organization we've developed a java application that exposes odata services, some technologies that we've used are:&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;UL&gt; 
   &lt;LI&gt;Spring Boot&lt;/LI&gt; 
   &lt;LI&gt;Apache Olingo&lt;/LI&gt; 
   &lt;LI&gt;JPA/Hibernate&lt;/LI&gt; 
  &lt;/UL&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;Everything seems to work fine, we can consume the odatas and do our requirements, but I've found a problem when performing a filter by date.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;Query:&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;WorkOrderHeaders?$filter=(StartDate ge datetime'2018-01-16T05:00:00')&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;Result:&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;QueryException: unexpected char: '{' [SELECT E1 FROM WorkOrderHeader E1 WHERE (E1.startDate &amp;gt;= {ts '2018-01-16 05:00:00.000'})]&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/176502-hiberntequery.png" /&gt;&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;I thought it was a problem of Olingo, so I did a research and found this article: &lt;A href="https://issues.apache.org/jira/browse/OLINGO-240?jql=text%20~%20%22datetime%20filter%22" target="test_blank"&gt;https://issues.apache.org/jira/browse/OLINGO-240?jql=text%20~%20%22datetime%20filter%22&lt;/A&gt;&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;It basically said: "This issue is specific to hibernate and currently there is no specific handling in Olingo JPA processor for hibernate."&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;Googling about hibernate I've found this: &lt;A href="https://hibernate.atlassian.net/browse/HHH-8653" target="test_blank"&gt;https://hibernate.atlassian.net/browse/HHH-8653&lt;/A&gt;&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;It mention: "The root of the problem seems to be that the Hibernate generated grammar does not include support for temporal literals"&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;So, apparently hibernate don't provide support for date literals.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;UL&gt; 
   &lt;LI&gt;Any ideas how to solve this issue?. &lt;/LI&gt; 
   &lt;LI&gt;Do I have to change JPA implementation?&lt;/LI&gt; 
  &lt;/UL&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;ps. I've builded a small project using the same technologies but considering eclipselink instead of hibernate and it works fine with date filters.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Mon, 30 Jul 2018 17:10:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/java-hibernate-odata-filter-by-datetime-is-not-working/qaq-p/744165</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2018-07-30T17:10:50Z</dc:date>
    </item>
    <item>
      <title>Re: Java/Hibernate odata filter by datetime is not working</title>
      <link>https://community.sap.com/t5/technology-q-a/java-hibernate-odata-filter-by-datetime-is-not-working/qaa-p/744166#M210378</link>
      <description>&lt;P&gt;Hi Ivan&lt;/P&gt;
  &lt;P&gt;Considering that you've made it work with EclipseLink, are there any reasons why you should be using hibernate instead?&lt;/P&gt;
  &lt;P&gt;BTW: SAP has delivers the library "&lt;A href="https://blogs.sap.com/2017/10/17/introducing-the-sap-cloud-platform-sdk-for-service-development/"&gt;SDK for Services&lt;/A&gt;" which is basically the same "logic" behind the new cloud foundry "&lt;A href="https://blogs.sap.com/2018/06/05/introducing-the-new-application-programming-model-for-sap-cloud-platform/"&gt;application programming model&lt;/A&gt;". With both technologies you are able to create your own OData services based on a DB entities with automation and simplification of the development process without sacrificing flexibility. I'd suggest looking into it as well. There os a nice &lt;A href="https://blogs.sap.com/2018/06/05/deep-dive-9-use-the-sap-s4hana-cloud-sdk-in-the-application-programming-model-for-sap-cloud-platform/"&gt;blog&lt;/A&gt; on how to create samples using this technologies. &lt;/P&gt;
  &lt;P&gt;Hope that helps.&lt;/P&gt;
  &lt;P&gt;Regards,&lt;BR /&gt;Ivan&lt;/P&gt;</description>
      <pubDate>Thu, 02 Aug 2018 21:05:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/java-hibernate-odata-filter-by-datetime-is-not-working/qaa-p/744166#M210378</guid>
      <dc:creator>Ivan-Mirisola</dc:creator>
      <dc:date>2018-08-02T21:05:53Z</dc:date>
    </item>
    <item>
      <title>Re: Java/Hibernate odata filter by datetime is not working</title>
      <link>https://community.sap.com/t5/technology-q-a/java-hibernate-odata-filter-by-datetime-is-not-working/qaa-p/744167#M210379</link>
      <description>&lt;P&gt;Hi Ivan.&lt;/P&gt;
  &lt;P&gt;Thanks for you answer, currently I'm testing the application looking for negative impacts because of the migration from Hibernate to EclipseLink.&lt;/P&gt;
  &lt;P&gt;Since our team has more experience working with hibernate, is there a way to fix this problem?&lt;/P&gt;</description>
      <pubDate>Sun, 12 Aug 2018 05:17:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/java-hibernate-odata-filter-by-datetime-is-not-working/qaa-p/744167#M210379</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2018-08-12T05:17:49Z</dc:date>
    </item>
    <item>
      <title>Re: Java/Hibernate odata filter by datetime is not working</title>
      <link>https://community.sap.com/t5/technology-q-a/java-hibernate-odata-filter-by-datetime-is-not-working/qaa-p/744168#M210380</link>
      <description>&lt;P&gt;Hi Ivan,&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;Please check the following tutorial on how to setup Hibernate for HANA in Eclipse. I think it might help you checking your project setup. &lt;/P&gt;
  &lt;P&gt;More specifically, check the following attribute on your hibernate persistence config:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;hibernate.dialect=org.hibernate.dialect.HANAColumnStoreDialect&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;The "unexpected char" tells me that hibernate is generating invalid SQL commands to your HANA DB (I am assuming you are trying to run your JPA project against a HABA DB. Am I correct?).&lt;/P&gt;
  &lt;P&gt;While checking the SQL command from the provided error I've noticed the usage of function 'ts'. This shows that hibernate isn't generating HANA compatible SQL code, as there is no such &lt;A href="https://help.sap.com/viewer/4fe29514fd584807ac9f2a04f6754767/2.0.01/en-US/209ddefe75191014ac249bf78ba2a1e9.html" target="_blank"&gt;data type conversion function&lt;/A&gt; on HANA. The closest SQL function that is perhaps equivalent to a time stamp conversion function taking as input a formatted string would be the &lt;A href="https://help.sap.com/viewer/4fe29514fd584807ac9f2a04f6754767/2.0.01/en-US/20f1a5b075191014b773acf0dc277cae.html" target="_blank"&gt;TO_TIMESTAMP.&lt;/A&gt; &lt;/P&gt;
  &lt;P&gt;I think that by setting the correct dialect, the generated SQL syntax will be correct.&lt;/P&gt;
  &lt;P&gt;I would also try running the same SQL commands seen on your Hibernate application against your DB via SQL Console. That way you will be able to figure out which part of the SQL command is wrong. &lt;/P&gt;
  &lt;P&gt;Best regards,&lt;BR /&gt;Ivan&lt;/P&gt;</description>
      <pubDate>Mon, 13 Aug 2018 14:04:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/java-hibernate-odata-filter-by-datetime-is-not-working/qaa-p/744168#M210380</guid>
      <dc:creator>Ivan-Mirisola</dc:creator>
      <dc:date>2018-08-13T14:04:33Z</dc:date>
    </item>
    <item>
      <title>Re: Java/Hibernate odata filter by datetime is not working</title>
      <link>https://community.sap.com/t5/technology-q-a/java-hibernate-odata-filter-by-datetime-is-not-working/qaa-p/744169#M210381</link>
      <description>&lt;P&gt;Hi Ivan.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;I've checked my project jpa configuration and it's ok. Yes I'm running with HANA DB.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;In this case "SELECT E1 FROM WorkOrderHeader E1 WHERE (E1.startDate &amp;gt;= {ts '2018-01-16 05:00:00.000'})" isn't SQL query, it's actually JPA query (JPQL). &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;The following odata filter "WorkOrderHeaders?$filter=(StartDate ge datetime'2018-01-16T05:00:00')" With olingo produces: "SELECT E1 FROM WorkOrderHeader E1 WHERE (E1.startDate &amp;gt;= {ts '2018-01-16 05:00:00.000'})"&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;The problem is that Hibernate do not support standard date literals, check this: &lt;A href="https://stackoverflow.com/questions/8386109/jpa-date-literal?noredirect=1&amp;amp;lq=1" target="test_blank"&gt;https://stackoverflow.com/questions/8386109/jpa-date-literal?noredirect=1&amp;amp;lq=1&lt;/A&gt;&lt;/P&gt;
  &lt;P&gt;It seems that the only option I have is to migrate to EclipseLink.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;Regards.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Mon, 20 Aug 2018 00:05:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/java-hibernate-odata-filter-by-datetime-is-not-working/qaa-p/744169#M210381</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2018-08-20T00:05:31Z</dc:date>
    </item>
    <item>
      <title>Re: Java/Hibernate odata filter by datetime is not working</title>
      <link>https://community.sap.com/t5/technology-q-a/java-hibernate-odata-filter-by-datetime-is-not-working/qaa-p/744170#M210382</link>
      <description>&lt;P&gt;Hi Ivan,&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;OK, now I understand what you are trying to do and the Hibernate limitations. However, the support for date literals is missing on version 4.2.5. &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;Could you check you are using a version of spring boot that carries a more recent version of hibernate-core?&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;Even for spring boot 1.5.16 you would be getting hibernate 5.0.12 - which may already have the fix for this issue you are having. Since you would be checking for a fix, I would go directly yo version 2.1.0 that contains hibernate-core 5.3.5.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;Regards,&lt;BR /&gt;Ivan&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Mon, 20 Aug 2018 17:47:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/java-hibernate-odata-filter-by-datetime-is-not-working/qaa-p/744170#M210382</guid>
      <dc:creator>Ivan-Mirisola</dc:creator>
      <dc:date>2018-08-20T17:47:02Z</dc:date>
    </item>
  </channel>
</rss>

