I need to the get lastest inserted ‘product’ in my database.
I’m using JPA (EclipseLink) to do that, something like :
public List<Product> search(String name){
// return the lastest results with the maximum of 100 values
}
How can I do that ?
Thanks.
Search for the products with the given name, order the results by insertion date (a column that must be present in the Product entity) of by ID (if using a sequence number as ID), in descending order, and call
setMaxResults(100)on the query to limit it to 100 results: