I honestly have some difficulty with BD, and I need a JPQL that returns only one record. I have an Entity Price and an Entity Product. I need to bring the last price registered by the user. I put a date and ID, I imagine it could be the last ID or even the last date (I have a date). But how do I do that? My DB is MYSQL and I'm using Hibernate, CDI and JSF.
Price table:
id | dataLancamento | value | .... product_id |
public Preco findByIdProdutoUltimoPreco(Integer produtoId) {
TypedQuery<Preco> query = em.createQuery(
"????",
Preco.class);
query.setParameter("pid", produtoId);
return query.getSingleResult();
}