Hql max value

3 respostas
F

por exemplo em sql…

SELECT MAX(Age) FROM Persons

e em hql??? como é??

3 Respostas

A

http://www.hibernate.org/347.html

select max(a.idade) form pessoas as a

P
consegui fazer o select , mas preciso capturar o valor inteiro da consulta , pois não encontrei nenhum metodo getInteger
public int getMaxIdInscricao(){
        int maxValue = 0 ;
    	Session sessao = HibernateUtility.getSession();
		Transaction tx = sessao.beginTransaction();
		int i;
		Query select = sessao.createQuery("select max(ev.INS_ID) from TB_EVENTOS as ev");
        
		tx.commit();
		sessao.close();
		return maxValue;	
    }
T

Já tentou pegar o list() da Query?
E depois da no List um get(0) que retorna um objeto?

Tipo...
List list = select.list();
int maxValue = (int)list.get(0);

ou

List list = select.list();
int maxValue = (int)list.uniqueResult();
Não testei o código... mas você pode fazer um teste!
Criado 21 de julho de 2006
Ultima resposta 24 de jul. de 2006
Respostas 3
Participantes 4