How to perform date operations in hibernate

前端 未结 8 1082
既然无缘
既然无缘 2020-12-10 03:00

I want to perform data time operations using hibernate HQL.

I want to add and subtract two dates as well as I want to subtract 1 year or 1 month from a particular da

8条回答
  •  青春惊慌失措
    2020-12-10 03:41

    You need to create your own dialect. Something like the following:

    public class MyDialect extends MySQLInnoDBDialect{
          public MyDialect() {
          super();
          registerFunction("date_add_interval", new SQLFunctionTemplate(Hibernate.DATE, "date_add(?1, INTERVAL ?2 ?3)"));
          }
        }
    

提交回复
热议问题