2
I am trying to perform a search only for the current date in a column timestamp, or without giving the time and yes only the date.
Model:
@DateTimeFormat(pattern = "dd/MM/yyyy hh:mm")
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "data")
private Date date;
I currently use Spring Data to perform the query.
Service class:
public List<Order> findByDate(){
return orderRepository.findByDate(new Date());
}
Spring Data repository:
@Repository
public interface OrderRepository extends JpaRepository<Order, Long> {
List<Order> findByDate(Date date);
}
The problem that the query
is made taking into account the current timestamp with minute and second hour values and I want the select
is made only by selecting the current date records.
Select with example Binding:
SELECT
order0_.id AS id1_1_,
order0_.data AS data2_1_,
order0_.pedido AS pedido3_1_,
order0_.pagamento AS pagament4_1_,
order0_.telefone AS telefone5_1_,
order0_.status AS status6_1_,
order0_.total AS total7_1_,
order0_.usuario AS usuario8_1_
FROM
spring_admin.pedidos_zuhause order0_
WHERE
order0_.data = ?;
Binding Parameter [1] as [TIMESTAMP] - [Wed Sep 20 10:15:35 BRT 2017]
I know I saw Mysql I can do this using the function date()
, but how can I do it for Hibernate?