@SuppressWarnings("unchecked") public NotaFiscalRemessa buscarPorIdListagemNotaFiscalSaida(final Long id) { Query q = sessionFactory .getCurrentSession() .createQuery( "SELECT h " + "FROM " + entityClass.getName() + " h " + "LEFT JOIN FETCH h.ordensServico os " + "LEFT JOIN FETCH h.volumes " + "LEFT JOIN FETCH h.cliente c " + "LEFT JOIN FETCH c.enderecos " + "WHERE h.id=:id"); q.setParameter("id", id); NotaFiscalRemessa r = (NotaFiscalRemessa) q.uniqueResult(); Query q2 = sessionFactory .getCurrentSession() .createQuery( "SELECT o FROM OrdemServico o " + "WHERE o.notaFiscalSaida.id = :id ORDER BY o.id"); q2.setParameter("id", id); List<OrdemServico> oss = q2.list(); if (oss != null) { r.setOrdensServico(new HashSet<OrdemServico>()); r.getOrdensServico().addAll(oss); } return r; }
@SuppressWarnings("unchecked") public List<OrdemServico> listarOrdemServicoPorNotaFiscalSaida( final NotaFiscalRemessa notaFiscalSaida) { Query q = sessionFactory .getCurrentSession() .createQuery( "SELECT NEW br.com.sose.entity.recebimento.OrdemServico(" + "o.id, " + "o.numeroOrdemServico, " + "o.serieCliente, " + "o.serieFabricante, " + "o.caseAvaya, " + "o.clienteAvaya, " + "up.numeroOrdemServico, " + "u.nome, " + "nf.numero," + "o.garantia," + "orc.condicao," + "rep.condicao," + "c.id," + "c.nomeSistema" + ") FROM OrdemServico o " + "LEFT JOIN o.cliente c " + "LEFT JOIN o.unidade u " + "LEFT JOIN o.unidadePai up " + "LEFT JOIN o.notaFiscal nf " + "LEFT JOIN o.orcamento orc " + "LEFT JOIN o.reparo rep " + "WHERE o.notaFiscalSaida.id = :notaFiscalSaida ORDER BY o.id"); q.setParameter("notaFiscalSaida", notaFiscalSaida.getId()); return q.list(); }