【发布时间】:2020-12-14 10:07:37
【问题描述】:
我正在使用 Spring Boot JPA 进行 CRUD 操作。我正在使用日期类型的字段名称 created_at 查询数据库表。表中有一些行具有给定的日期,但 JPA 给出的结果集为零。我正在使用 Oracle 11g
这是我的实体
import java.sql.Date;
@Entity
@Table(name="veev_json")
public class VeevJson {
@Id
@Column(name="ID")
private int id;
@Column(name="CREATED_AT")
private Date createdDate;
}
我的 JPA 存储库
import java.util.Date;
@Repository
public interface VeevJsonRepository extends JpaRepository<VeevJson, Integer> {
public List<VeevJson> findByCreatedDate(Date date);
}
在服务层调用函数
Date date = new Date(); //taking current date of type java.util.Date
List<VeevJson> documents = veevJsonRepository.findByCreatedDate(date);
我的数据库表结构
ID NUMBER(10,0)
CREATED_AT DATE
hibernate生成的SQL查询:
select veevjson0_.ID as ID1_1_, veevjson0_.CREATED_AT as CREATED_AT2_1_, veevjson0_.JSON as JSON3_1_, veevjson0_.STATUS as STATUS4_1_ from veev_json veevjson0_ where veevjson0_.CREATED_AT=?
【问题讨论】:
标签: java spring-boot hibernate jpa