hibernate - EntityManager query.getResultList() returning empty list -
i beginner @ hibernate , jpa, trying retrieve list of items database via entitymanager query.getresultlist() doesn't return anything. here bean searching data: `
import java.util.list; import javax.faces.bean.managedbean; import javax.faces.bean.viewscoped; import javax.persistence.entitymanager; import javax.persistence.typedquery; import com.algaworks.financeiro.model.lancamento; import com.algaworks.financeiro.util.jpautil; @managedbean @viewscoped public class consultalancamentosbean { private list<lancamento> lancamentos; public void consultar() { entitymanager manager = jpautil.getentitymanager(); typedquery<lancamento> query = manager.createquery ( "from lancamento", lancamento.class ); this.lancamentos = query.getresultlist(); manager.close(); } public list<lancamento> getlancamentos() { return lancamentos; } } the view searching bean: `
<!doctype html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:h="http://xmlns.jcp.org/jsf/html"> <h:head> <title>consulta de lançamentos</title> </h:head> <h:body> <f:metadata> <f:viewaction action="#{consultalancamentosbean.consultar}" /> </f:metadata> <h1>consulta de lançamentos</h1> <h:form id="frm"> <h:datatable value="#{consultalancamentosbean.lancamentos}" var="lancamento" border="1" cellspacing="0" cellpadding="2"> <h:column> <f:facet name="header"> <h:outputtext value="pessoa"/> </f:facet> <h:outputtext value="#{lancamento.pessoa.nome}"/> </h:column> <h:column> <f:facet name="header"> <h:outputtext value="descrição"/> </f:facet> <h:outputtext value="#{lancamento.descricao}"/> </h:column> <h:column> <f:facet name="header"> <h:outputtext value="tipo"/> </f:facet> <h:outputtext value="#{lancamento.tipo}"/> </h:column> <h:column> <f:facet name="header"> <h:outputtext value="valor"/> </f:facet> <h:outputtext value="#{lancamento.valor}"/> </h:column> <h:column> <f:facet name="header"> <h:outputtext value="data de vencimento"/> </f:facet> <h:outputtext value="#{lancamento.datavencimento}"/> </h:column> <h:column> <f:facet name="header"> <h:outputtext value="data de pagamento"/> </f:facet> <h:outputtext value="#{lancamento.datapagamento}"/> </h:column> </h:datatable> </h:form> </h:body> </html> the getlancamentos() returns empty list, know why happening? in advance
update: have verified right connection , tables have data, changed bean have 1 method: `
public list<lancamento> getlancamentos() { entitymanager manager = jpautil.getentitymanager(); typedquery<lancamento> query = manager.createquery("select lan lancamento lan", lancamento.class); list<lancamento> lancamentos; lancamentos = query.getresultlist(); return lancamentos; } , new view is:
<!doctype html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:h="http://xmlns.jcp.org/jsf/html"> <h:head> <title>the size is:</title> <h:outputlabel value="#{consultalancamentosbean.lancamentos}"> </h:outputlabel> </html> `
but now, when try run code displays: http status 500 - not initialize class com.algaworks.financeiro.util.jpautil
i have imported class
try this:
typedquery<lancamento> query = manager.createquery("select lan lancamento lan", lancamento.class); lancamentos = query.getresultlist(); your query specifying select
Comments
Post a Comment