I am trying to perform a search only for the current date in a timestamp column, ie without informing the time, but only the date.
Template:
@DateTimeFormat(pattern = "dd/MM/yyyy hh:mm")
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "data")
private Date date;
I currently use Spring Data to conduct the query.
Class of service:
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 query
is made taking into account the current timestamp with minute and second hour values and I want select
to be done just by selecting the current date records.
Select with the 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 could see MySQL I can do this using the date()
function, but how can I do this by hibernate ?