Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 如何使用Hibernate根据当前日期查询数据库?_Spring Boot_Hibernate - Fatal编程技术网

Spring boot 如何使用Hibernate根据当前日期查询数据库?

Spring boot 如何使用Hibernate根据当前日期查询数据库?,spring-boot,hibernate,Spring Boot,Hibernate,我想根据当天检索数据库项 为此,我尝试使用前面解释和提到的day()函数 我有一个“创建”日期字段,在表中创建新项目时自动填充该字段。它使用模型进行配置,如下所示: @Column(name = "created", nullable = false) @CreationTimestamp private Date created; 我创建了两个项目,并按预期在数据库中填写了日期 现在,我尝试使用HQL查询调用这些项: String hql = ""

我想根据当天检索数据库项

为此,我尝试使用前面解释和提到的
day()
函数

我有一个“创建”日期字段,在表中创建新项目时自动填充该字段。它使用模型进行配置,如下所示:

@Column(name = "created", nullable = false)
@CreationTimestamp
private Date created;
我创建了两个项目,并按预期在数据库中填写了日期

现在,我尝试使用HQL查询调用这些项:

String hql = "" +
  "FROM Item as item " +
  "WHERE item.itemId = ?1" +
  "AND item.created = day(current_date())";
问题是此查询返回的是NoResultException

这很奇怪,因为我在其他场景中使用了
current\u date()
函数,例如:

String hql = "" +
  "FROM Item as item " +
  "WHERE item.itemId = ?1" +
  "AND item.createdAt >= current_date - ?2";
而且它工作得很好

因此,我假设问题与
day()
函数有关。

尝试使用以下方法:

String hql = "" +
  "FROM Item as item " +
  "WHERE item.itemId = ?1" +
  "AND date(item.created) = current_date()";