Pesquisa por datas usando namedQuery pegar valor total da venda

0 respostas
java
E

Olá pessoal, creio que seja erro na logica pois testei a “query” no phpmyadmin e consigo obter a soma com o “sum” porem ao clicar no botao aparece excption null;

domain - FECHAMENTOCAIXA
`

@NamedQuery(name="Venda.buscarTotalMovimencaoVenda",query="SELECT sum(venda.valor_total)FROM Venda venda where venda.horario BETWEEN :data_inicial_relatorio  AND :data_final_relatorio")

@Temporal(TemporalType.TIMESTAMP)
@Column(name="horario_fechamento", nullable=false)
private Date horario_fechamento;

@Temporal(TemporalType.DATE)
@Column(name="data_inicial_relatorio", nullable=false)
private Date data_inicial_relatorio;

@Temporal(TemporalType.DATE)
@Column(name="data_final_relatorio", nullable=false)
private Date data_final_relatorio;

DAO
public FechamentoCaixa buscarPorData(Date data_inicial_relatorio,Date data_final_relatorio ) {
Session sessao = HibernateUtil.getFabricaDeSessoes().openSession();
FechamentoCaixa fechamentoCaixa = null;

try {
		Query consulta = (Query) sessao.getNamedQuery("Venda.buscarPorData");
		((org.hibernate.Query) consulta).setDate("data_inicial_relatorio", data_inicial_relatorio);
		((org.hibernate.Query) consulta).setDate("data_final_relatorio", data_final_relatorio);
		fechamentoCaixa = (FechamentoCaixa) ((org.hibernate.Query) consulta).uniqueResult();
		System.out.println(fechamentoCaixa);
	} catch (RuntimeException erro) {
		throw erro;
	} finally {
		sessao.close();
	}
	return fechamentoCaixa;
}

`

FECHAMENTOCAIXABEAN

`public void carregarCadastro() {

try {

if (fechamentoCaixaCadastro.getData_inicial_relatorio() != null || fechamentoCaixaCadastro.getData_final_relatorio() != null ) {
FechamentoCaixaDAO fechamentoCaixaDAO = new FechamentoCaixaDAO();
			fechamentoCaixaCadastro = fechamentoCaixaDAO.buscarPorData(fechamentoCaixaCadastro.getData_inicial_relatorio(),fechamentoCaixaCadastro.getData_final_relatorio());
			fechamentoCaixaCadastro.setValor_venda(valor_total_venda);
		}else{
			}
	} catch (RuntimeException ex) {
		FacesUtil.adicionarMsgErro("Erro ao carregar obter os dados: "+ ex.getMessage());
	}`

XHTML

<ui:composition template="/templates/modeloPadrao.xhtml"> <ui:define name="metadata"> <f:metadata> <f:event listener="#{fechamentoCaixaBean.carregarCadastro}" type="preRenderView" /> </f:metadata> </ui:define> <ui:define name="conteudo"> <h:form id="frmVendasPesquisas">
` <p:toolbar>
<f:facet name=“left”>
<h:outputText value=“Pesquisa de Vendas” />
</f:facet>
</p:toolbar>

<h:panelGrid columns="7" tyle="text-align: center;">
			<p:outputLabel value="Data Inicial:"/>
			<p:calendar value="#{fechamentoCaixaBean.data_inicial_relatorio}" />
										
			<p:outputLabel value="Data Inicial:"/>
			<p:calendar value="#{fechamentoCaixaBean.data_final_relatorio}" />

			<p:commandButton value="Buscar" icon="ui-icon-search"
				actionListener="#{fechamentoCaixaBean.carregarCadastro}"
				update=":msgGlobal :frmVendasPesquisas"> 
			</p:commandButton>

	<h:outputText value="Resultado da Busca" />		
	<h:outputText value="#{fechamentoCaixaBean.fechamentoCaixaCadastro.valor_venda}"/>			
			</h:panelGrid>
	</h:form>
		</ui:define>

</ui:composition>

`

ERROR
[Ljava.lang.StackTraceElement;@1c7e2e5

Advertencia
jan 18, 2016 5:52:04 PM com.sun.faces.context.flash.ELFlash setCookie ADVERTÊNCIA: JSF1095: The response was already committed by the time we tried to set the outgoing cookie for the flash. Any values stored to the flash will not be available on the next request.

Criado 18 de janeiro de 2016
Respostas 0
Participantes 1