1

我有一个 postgres 数据库,它有一个"draft"包含 set_up_time 列的表,保存为时间戳:

@Column(nullable = false)
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
LocalDateTime setUpTime;

由于某些原因,我需要保持这种结构不变。但是我期待数据库查询searching for records, for setUpTime as LocalDateTime and setUpTime as LocalDate。如何以某种方式映射它,即休眠使用这两种类型的 setUpTime 查询数据库,并相应地返回结果?

我使用的架构是:

"create table draft (dtype varchar(31) not null, id int8 not null, creation_time timestamp not null, cust_ord varchar(1), description varchar(255), amount decimal(12, 2), user varchar(6), txn_time timestamp, text1from varchar(36), text2from varchar(36), text3from varchar(36), primary key (id))"
4

1 回答 1

0

你可以做的是这样写你的查询:

public void findDrafts(LocalDate targetDate) {
    final Query query = entityManager.createQuery(
      "from Draft where setUpTime => :beginOfDay and setUpTime < :beginOfNextDay");
    query.setParameter("beginOfDay", targetDate.toDateTimeAtStartOfDay().toLocalDateTime());
    query.setParameter("beginOfNextDay", targetDate.plusDays(1).toDateTimeAtStartOfDay().toLocalDateTime());
    return query.getResultList();
}
于 2013-05-29T13:51:29.783 回答