Collection custoso usar .size()?  XML
Índice dos Fóruns » Java Avançado
Autor Mensagem
phstc
JavaGuru

Membro desde: 13/04/2004 12:22:22
Mensagens: 200
Localização: São Paulo, SP
Offline

Pessoal,

Acho muito custoso ficar pegando o .size(), de uma collection ( Set ) para saber por exemplo
quantos Topicos tem em um Forum ( forum.getTopicos().size() ).

Pensei em fazer um metodo getTopicoSize() lazy="true", que pega o SELECT COUNT de um tabela,
caso a collection não tenha sido carregada, caso contrario retorna collection.size().


Vocês sabem como fazer isso com hibernate? Tem outra solução melhor?

[]'s,
Pablo
[Email]
Filipe Sabella
GUJ Expert

Membro desde: 12/03/2003 11:25:57
Mensagens: 4680
Offline


You can use the filter() method of the Hibernate Session API to get the size of a collection without initializing it:

( (Integer) s.filter( collection, "select count(*)" ).get(0) ).intValue()

filter() or createFilter() are also used to efficiently retrieve subsets of a collection without needing to initialize the whole collection.


http://www.hibernate.org/hib_docs/reference/en/html/collections.html

Former LIPE.
[ICQ]
 
Índice dos Fóruns » Java Avançado
Ir para:   
Powered by JForum 2.1.8 © JForum Team