Bom dia Galera estou aqui mais uma vez pra pedir ajuda de vcs.
Seguinte tenho uma view no banco de dados com algumas funções tb feitas no banco de dados, essa view traz dados de datas calculadas.
Aqui é onde eu faço minha busca pra me retornar os valores da minha view.
publicList<EtapaView>todasEtapasView(intidclasse,intidaval){
System.out.println("todasEtapasView");session=HibernateUtil.getInstance();Stringquery=" SELECT epv FROM EtapaView epv, Classe c, Prova p "+" WHERE epv.id.idaval = p.idaval "+" AND epv.id.idclasse = c.idclasse "+" AND c.idclasse = "+idclasse+" AND p.idaval = "+idaval;System.out.println("query "+query);Listq=session.createQuery(query).list();System.out.println("etapa padrao List "+q); //<------- Só que o retorno é esse "etapa padrao List [null, null, null, null, null]"returnq;}
Testei essa query no banco de dados ele me retornou os dados certinhos.
Estou na dúvida pq que os arrays mostrados acima estão vindo null.
Pois na minha datatable da minha jsf eu soh quero mostrar os dados da view do banco, pois já estão calculados.
Só uma dica.
Não use concatenação de String para criar a consulta.
Além da nada performático, afinal cada vez que você concatena uma String com outra uma terceira é criada.
Use StringBuilder com o método append.
Outra coisa esquisita aí é que você está usando o hibernate não é.
No hibernate você pode referenciar os atributos por nomes.
Assim.
session = HibernateUtil.getInstance();
StringBuilder sql = new StringBuilder();
sql.append("SELECT epv FROM EtapaView epv, Classe c, Prova p ");
sql.append("WHERE epv.id.idaval = p.idaval AND epv.id.idclasse = c.idclasse" );
sql.append(" AND c.idclasse = :idClasse" );
sql.append("AND p.idaval = :idaval ");
Query q = session.createQuery(sql.toString());
q.setParameter("idClasse",idclasse);
q.setParameter("idaval",idaval);
List lista = q.list();
Tenta fazer assim para ver se retorna.
Só uma curiosidade.
Você está usando oracle ?
cherador
e aew lele_vader blz??
Primeiramente vlw a dica sempre é bom conversar com outras pessoas que entendem de programação. Aqui onde trabalho eu sou tudo DBA, Analista, Programador e por aí vai.
Pow entaum olhei aqui fiz o teste e o retorno foi o mesmo.
Sim estou usando Hibernate e Postgresql
Engraçado que em outra jsf eu mostro uma view toda calculada bunitinho.
Tipo assim as functions do banco podem influenciar em alguma coisa??
pois essa view EtapaView utiliza functions no banco e tem valor necessário pra mostrar pro user.
publicListtodasEtapasView(intidclasse,intidaval){System.out.println("todasEtapasView");session=HibernateUtil.getInstance();StringBuildersql=newStringBuilder();sql.append(" SELECT epv FROM EtapaView epv, Classe c, Prova p ");sql.append(" WHERE epv.id.idaval = p.idaval AND epv.id.idclasse = c.idclasse ");sql.append(" AND c.idclasse = :idClasse ");sql.append(" AND p.idaval = :idaval ");Queryq=session.createQuery(sql.toString());q.setParameter("idClasse",idclasse);q.setParameter("idaval",idaval);Listlista=q.list();System.out.println("query "+q);// query QueryImpl( SELECT epv FROM EtapaView epv, Classe c, Prova p WHERE epv.id.idaval = p.idaval AND epv.id.idclasse = c.idclasse AND c.idclasse = :idClasse AND p.idaval = :idaval )System.out.println("etapa padrao List "+lista);// etapa padrao List [null, null, null, null, null]returnlista;}
lele_vader
Essa etapaView está mapeada em uma classe ?
Pode mostra-la ?
cherador
segue minha EtapaView.hbm.xml
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><!-- Generated 05/07/2012 11:34:23 by Hibernate Tools 3.2.1.GA --><hibernate-mapping><classname="model.view.EtapaView"schema="public"table="c_etapa"><composite-idclass="model.view.EtapaViewId"name="id"><key-propertyname="etapa"type="string"><columnlength="100"name="etapa"/></key-property><key-propertyname="idaval"type="java.lang.Integer"><columnname="idaval"/></key-property><key-propertyname="idclasse"type="java.lang.Integer"><columnname="idclasse"/></key-property><key-propertyname="idetapa"type="java.lang.Integer"><columnname="idetapa"/></key-property><key-propertyname="dtinicio"type="timestamp"><columnlength="29"name="dtinicio"/></key-property><key-propertyname="dtfim"type="timestamp"><columnlength="29"name="dtfim"/></key-property><key-propertyname="dtinicioprevisao"type="timestamp"><columnlength="29"name="dtinicioprevisao"/></key-property><key-propertyname="obs"type="string"><columnname="obs"/></key-property><key-propertyname="feriadoprevisao"type="java.lang.Short"><columnname="feriadoprevisao"/></key-property><key-propertyname="feriadoefetivo"type="java.lang.Short"><columnname="feriadoefetivo"/></key-property><key-propertyname="duracaoprevista"type="java.lang.Float"><columnname="duracaoprevista"precision="8"scale="8"/></key-property><key-propertyname="retardo"type="java.lang.Short"><columnname="retardo"/></key-property><key-propertyname="duracaoefetiva"type="java.lang.Double"><columnname="duracaoefetiva"precision="17"scale="17"/></key-property><key-propertyname="terminoprevisto"type="date"><columnlength="13"name="terminoprevisto"/></key-property></composite-id></class></hibernate-mapping>
minha EtapaViewId.java
packagemodel.view;// Generated 05/07/2012 11:34:19 by Hibernate Tools 3.2.1.GAimportjava.util.Date;/** * CEtapaId generated by hbm2java */publicclassEtapaViewIdimplementsjava.io.Serializable{privateStringetapa;privateIntegeridaval;privateIntegeridclasse;privateIntegeridetapa;privateDatedtinicio;privateDatedtfim;privateDatedtinicioprevisao;privateStringobs;privateShortferiadoprevisao;privateShortferiadoefetivo;privateFloatduracaoprevista;privateShortretardo;privateDoubleduracaoefetiva;privateDateterminoprevisto;publicEtapaViewId(){}publicEtapaViewId(Stringetapa,Integeridaval,Integeridclasse,Integeridetapa,Datedtinicio,Datedtfim,Datedtinicioprevisao,Stringobs,Shortferiadoprevisao,Shortferiadoefetivo,Floatduracaoprevista,Shortretardo,Doubleduracaoefetiva,Dateterminoprevisto){this.etapa=etapa;this.idaval=idaval;this.idclasse=idclasse;this.idetapa=idetapa;this.dtinicio=dtinicio;this.dtfim=dtfim;this.dtinicioprevisao=dtinicioprevisao;this.obs=obs;this.feriadoprevisao=feriadoprevisao;this.feriadoefetivo=feriadoefetivo;this.duracaoprevista=duracaoprevista;this.retardo=retardo;this.duracaoefetiva=duracaoefetiva;this.terminoprevisto=terminoprevisto;}publicStringgetEtapa(){returnthis.etapa;}publicvoidsetEtapa(Stringetapa){this.etapa=etapa;}publicIntegergetIdaval(){returnthis.idaval;}publicvoidsetIdaval(Integeridaval){this.idaval=idaval;}publicIntegergetIdclasse(){returnthis.idclasse;}publicvoidsetIdclasse(Integeridclasse){this.idclasse=idclasse;}publicIntegergetIdetapa(){returnthis.idetapa;}publicvoidsetIdetapa(Integeridetapa){this.idetapa=idetapa;}publicDategetDtinicio(){returnthis.dtinicio;}publicvoidsetDtinicio(Datedtinicio){this.dtinicio=dtinicio;}publicDategetDtfim(){returnthis.dtfim;}publicvoidsetDtfim(Datedtfim){this.dtfim=dtfim;}publicDategetDtinicioprevisao(){returnthis.dtinicioprevisao;}publicvoidsetDtinicioprevisao(Datedtinicioprevisao){this.dtinicioprevisao=dtinicioprevisao;}publicStringgetObs(){returnthis.obs;}publicvoidsetObs(Stringobs){this.obs=obs;}publicShortgetFeriadoprevisao(){returnthis.feriadoprevisao;}publicvoidsetFeriadoprevisao(Shortferiadoprevisao){this.feriadoprevisao=feriadoprevisao;}publicShortgetFeriadoefetivo(){returnthis.feriadoefetivo;}publicvoidsetFeriadoefetivo(Shortferiadoefetivo){this.feriadoefetivo=feriadoefetivo;}publicFloatgetDuracaoprevista(){returnthis.duracaoprevista;}publicvoidsetDuracaoprevista(Floatduracaoprevista){this.duracaoprevista=duracaoprevista;}publicShortgetRetardo(){returnthis.retardo;}publicvoidsetRetardo(Shortretardo){this.retardo=retardo;}publicDoublegetDuracaoefetiva(){returnthis.duracaoefetiva;}publicvoidsetDuracaoefetiva(Doubleduracaoefetiva){this.duracaoefetiva=duracaoefetiva;}publicDategetTerminoprevisto(){returnthis.terminoprevisto;}publicvoidsetTerminoprevisto(Dateterminoprevisto){this.terminoprevisto=terminoprevisto;}publicbooleanequals(Objectother){if((this==other))returntrue;if((other==null))returnfalse;if(!(otherinstanceofEtapaViewId))returnfalse;EtapaViewIdcastOther=(EtapaViewId)other;return((this.getEtapa()==castOther.getEtapa())||(this.getEtapa()!=null&&castOther.getEtapa()!=null&&this.getEtapa().equals(castOther.getEtapa())))&&((this.getIdaval()==castOther.getIdaval())||(this.getIdaval()!=null&&castOther.getIdaval()!=null&&this.getIdaval().equals(castOther.getIdaval())))&&((this.getIdclasse()==castOther.getIdclasse())||(this.getIdclasse()!=null&&castOther.getIdclasse()!=null&&this.getIdclasse().equals(castOther.getIdclasse())))&&((this.getIdetapa()==castOther.getIdetapa())||(this.getIdetapa()!=null&&castOther.getIdetapa()!=null&&this.getIdetapa().equals(castOther.getIdetapa())))&&((this.getDtinicio()==castOther.getDtinicio())||(this.getDtinicio()!=null&&castOther.getDtinicio()!=null&&this.getDtinicio().equals(castOther.getDtinicio())))&&((this.getDtfim()==castOther.getDtfim())||(this.getDtfim()!=null&&castOther.getDtfim()!=null&&this.getDtfim().equals(castOther.getDtfim())))&&((this.getDtinicioprevisao()==castOther.getDtinicioprevisao())||(this.getDtinicioprevisao()!=null&&castOther.getDtinicioprevisao()!=null&&this.getDtinicioprevisao().equals(castOther.getDtinicioprevisao())))&&((this.getObs()==castOther.getObs())||(this.getObs()!=null&&castOther.getObs()!=null&&this.getObs().equals(castOther.getObs())))&&((this.getFeriadoprevisao()==castOther.getFeriadoprevisao())||(this.getFeriadoprevisao()!=null&&castOther.getFeriadoprevisao()!=null&&this.getFeriadoprevisao().equals(castOther.getFeriadoprevisao())))&&((this.getFeriadoefetivo()==castOther.getFeriadoefetivo())||(this.getFeriadoefetivo()!=null&&castOther.getFeriadoefetivo()!=null&&this.getFeriadoefetivo().equals(castOther.getFeriadoefetivo())))&&((this.getDuracaoprevista()==castOther.getDuracaoprevista())||(this.getDuracaoprevista()!=null&&castOther.getDuracaoprevista()!=null&&this.getDuracaoprevista().equals(castOther.getDuracaoprevista())))&&((this.getRetardo()==castOther.getRetardo())||(this.getRetardo()!=null&&castOther.getRetardo()!=null&&this.getRetardo().equals(castOther.getRetardo())))&&((this.getDuracaoefetiva()==castOther.getDuracaoefetiva())||(this.getDuracaoefetiva()!=null&&castOther.getDuracaoefetiva()!=null&&this.getDuracaoefetiva().equals(castOther.getDuracaoefetiva())))&&((this.getTerminoprevisto()==castOther.getTerminoprevisto())||(this.getTerminoprevisto()!=null&&castOther.getTerminoprevisto()!=null&&this.getTerminoprevisto().equals(castOther.getTerminoprevisto())));}publicinthashCode(){intresult=17;result=37*result+(getEtapa()==null?0:this.getEtapa().hashCode());result=37*result+(getIdaval()==null?0:this.getIdaval().hashCode());result=37*result+(getIdclasse()==null?0:this.getIdclasse().hashCode());result=37*result+(getIdetapa()==null?0:this.getIdetapa().hashCode());result=37*result+(getDtinicio()==null?0:this.getDtinicio().hashCode());result=37*result+(getDtfim()==null?0:this.getDtfim().hashCode());result=37*result+(getDtinicioprevisao()==null?0:this.getDtinicioprevisao().hashCode());result=37*result+(getObs()==null?0:this.getObs().hashCode());result=37*result+(getFeriadoprevisao()==null?0:this.getFeriadoprevisao().hashCode());result=37*result+(getFeriadoefetivo()==null?0:this.getFeriadoefetivo().hashCode());result=37*result+(getDuracaoprevista()==null?0:this.getDuracaoprevista().hashCode());result=37*result+(getRetardo()==null?0:this.getRetardo().hashCode());result=37*result+(getDuracaoefetiva()==null?0:this.getDuracaoefetiva().hashCode());result=37*result+(getTerminoprevisto()==null?0:this.getTerminoprevisto().hashCode());returnresult;}}
e minha EtapaView.java
packagemodel.view;// Generated 05/07/2012 11:34:19 by Hibernate Tools 3.2.1.GA/** * CEtapa generated by hbm2java */publicclassEtapaViewimplementsjava.io.Serializable{privateEtapaViewIdid;publicEtapaView(){}publicEtapaView(EtapaViewIdid){this.id=id;}publicEtapaViewIdgetId(){returnthis.id;}publicvoidsetId(EtapaViewIdid){this.id=id;}}