Hibernate Dialects + datediff function

前端 未结 1 1336
失恋的感觉
失恋的感觉 2021-01-15 00:30

I have a problem in that the syntax for datediff in mysql is different from that in hsqldb:

mysql: datediff(date1,date2)
hsqldb: datediff(interval,date1,date         


        
相关标签:
1条回答
  • 2021-01-15 01:05

    I would say that the easiest solution is to create your own custom HSQLDB dialect, extending the existing HSQLDB dialect. Then, in the constructor, register a function to handle datediff(date1, date2) to be translated into datediff(interval, date1, date2), provided that interval would be a static value. Something like this:

    registerFunction( "datediff", new SQLFunctionTemplate( StandardBasicTypes.INTEGER, "datediff(interval, ?1, ?2)" ) );
    
    0 讨论(0)
提交回复
热议问题