Como faço para listar os últimos N registros de uma tabela T ordenados em ordem decrescente? estou utilizando Postgre e hibernate.
Ex:
1
2
3
4
5
6
7
8
9
10
Ou ultimos 3 decrescente seriam
10
9
8
Como faço para listar os últimos N registros de uma tabela T ordenados em ordem decrescente? estou utilizando Postgre e hibernate.
Ex:
1
2
3
4
5
6
7
8
9
10
Ou ultimos 3 decrescente seriam
10
9
8
Como faço para listar os últimos N registros de uma tabela T ordenados em ordem decrescente? estou utilizando Postgre e hibernate.Ex:
1
2
3
4
5
6
7
8
9
10Ou ultimos 3 decrescente seriam
10
9
8
Olá…
Acho que deseja o Limit (http://www.postgresql.org/docs/8.1/static/queries-limit.html) usado junto com o order by desc.
Abraços.
Obrigado, sua dica ajudou, abaixo segue a implementação que funcionou.
public Collection<?> listTabelaOrdenado(String column, int ordem, int N)
{
List resultado = null;
Session session = null;
try
{
session = HibernateUtil.getSession();
String order = "ASC";
if (ordem != 0)
order = "DESC";
resultado = session.createQuery("from Cliente cliente order by " + column + " " + order).setMaxResults(N).list();
HibernateUtil.closeSession();
}
catch (HibernateException ex)
{
throw new PersistenceException(ex);
}
return resultado;
}