Hibernate Repete consulta sql no jsf

3 respostas
tenclar

olá pessoal, tenho o seguinte código para listar os estados de um banco :

public class EstadoBean implements Serializable {
     private List<Estado> listaEstado = null;
    private EstadoDAO estadoDAO = new EstadoDAO();


      public List getListaEstados(){
           if(this.listaEstado == null); {
               this.listaEstado = estadoDAO.getEstados();
          }

        return this.listaEstado;
    }

      public void saveEstado(ActionEvent actionEvent){
        context = FacesContext.getCurrentInstance();        
                estadoDAO.saveEstado(this.estado);
               this.listaEstado = null;       
       
    }


}

o hibernate retorna a seguinte consulta :

INFO: Hibernate: 
    select
        estado0_.id as id0_,
        estado0_.nome as nome0_,
        estado0_.sigla as sigla0_ 
    from
        Estado estado0_ 
    order by
        estado0_.id desc
INFO: Hibernate: 
    select
        estado0_.id as id0_,
        estado0_.nome as nome0_,
        estado0_.sigla as sigla0_ 
    from
        Estado estado0_ 
    order by
        estado0_.id desc

o que poderia ser com que faz a repetição de consulta no hibernate?

3 Respostas

Rodrigo_Sasaki

Poste aí o trecho de código onde você chama o método getListaEstados(), se possível

tenclar
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>Lista de Estado</title>
    </h:head>
    <h:body>       
        <h:form>           
                <p:dataTable id="tabUf" var="item" [b]value="#{estadoBean.listaEstados}" [/b] style="width: 300px;height: auto; text-align: center;" paginatorPosition="bottom"  paginator="true"  paginatorAlwaysVisible="false" rows="6" >
                    <p:column style="text-align: center;">
                        <f:facet name="header">
                            <h:outputText value="Código" />
                        </f:facet>
                        <h:outputText value="#{item.id}" />
                    </p:column  >
                    <p:column style="text-align: center;" >
                        <f:facet name="header">
                            <h:outputText value="Sigla"/>
                        </f:facet>
                        <h:outputText value="#{item.sigla}"/>
                    </p:column>                       

                    <p:column style="text-align: center;" >
                        <f:facet name="header">
                            <h:outputText value="Nome"/>
                        </f:facet>
                        <h:outputText value="#{item.nome}"/>
                    </p:column>                       

                    <p:column style="text-align: center;">
                        <f:facet name="header">
                            <h:outputText value="Alterar"/>
                        </f:facet>
                        <p:commandButton  image="ui-icon ui-icon-refresh" actionListener="#{estadoBean.editEstado}" update="infoEstado" oncomplete="dialogGerUf.show()"/>

                    </p:column>

                </p:dataTable>

            </p:outputPanel >
        </h:form>
    </h:body>
</html>
tenclar

alguem me ajude por favor !

Criado 1 de dezembro de 2011
Ultima resposta 5 de dez. de 2011
Respostas 3
Participantes 2