List of usage examples for org.hibernate Query setShort
@Deprecated @SuppressWarnings("unchecked") default Query<R> setShort(String name, short val)
From source file:com.cloud.bridge.util.QueryHelper.java
License:Open Source License
public static void bindParameters(Query query, Object[] params) { int pos = 0;//from w w w . j av a 2 s .c om if (params != null && params.length > 0) { for (Object param : params) { if (param instanceof Byte) query.setByte(pos++, ((Byte) param).byteValue()); else if (param instanceof Short) query.setShort(pos++, ((Short) param).shortValue()); else if (param instanceof Integer) query.setInteger(pos++, ((Integer) param).intValue()); else if (param instanceof Long) query.setLong(pos++, ((Long) param).longValue()); else if (param instanceof Float) query.setFloat(pos++, ((Float) param).floatValue()); else if (param instanceof Double) query.setDouble(pos++, ((Double) param).doubleValue()); else if (param instanceof Boolean) query.setBoolean(pos++, ((Boolean) param).booleanValue()); else if (param instanceof Character) query.setCharacter(pos++, ((Character) param).charValue()); else if (param instanceof Date) query.setDate(pos++, (Date) param); else if (param instanceof Calendar) query.setCalendar(pos++, (Calendar) param); else if (param instanceof CalendarDateParam) query.setCalendarDate(pos++, ((CalendarDateParam) param).dateValue()); else if (param instanceof TimestampParam) query.setTimestamp(pos++, ((TimestampParam) param).timestampValue()); else if (param instanceof TimeParam) query.setTime(pos++, ((TimeParam) param).timeValue()); else if (param instanceof String) query.setString(pos++, (String) param); else if (param instanceof TextParam) query.setText(pos++, ((TextParam) param).textValue()); else if (param instanceof byte[]) query.setBinary(pos++, (byte[]) param); else if (param instanceof BigDecimal) query.setBigDecimal(pos++, (BigDecimal) param); else if (param instanceof BigInteger) query.setBigInteger(pos++, (BigInteger) param); else if (param instanceof Locale) query.setLocale(pos++, (Locale) param); else if (param instanceof EntityParam) query.setEntity(pos++, ((EntityParam) param).entityValue()); else if (param instanceof Serializable) query.setSerializable(pos++, (Serializable) param); else query.setEntity(pos++, param); } } }
From source file:com.enonic.cms.store.dao.ContentIndexEntityDao.java
License:Open Source License
public List<ContentKey> findContentKeysByQuery(final String hqlQuery, final Map<String, Object> parameters, final boolean cacheable) { return executeListResult(ContentKey.class, new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query compiled = session.createQuery(hqlQuery); compiled.setCacheable(cacheable); for (String key : parameters.keySet()) { Object value = parameters.get(key); if (value instanceof Date) { compiled.setTimestamp(key, (Date) value); } else if (value instanceof String) { compiled.setString(key, (String) value); } else if (value instanceof Boolean) { compiled.setBoolean(key, (Boolean) value); } else if (value instanceof Long) { compiled.setLong(key, (Long) value); } else if (value instanceof Integer) { compiled.setInteger(key, (Integer) value); } else if (value instanceof Byte) { compiled.setByte(key, (Byte) value); } else if (value instanceof byte[]) { compiled.setBinary(key, (byte[]) value); } else if (value instanceof Float) { compiled.setFloat(key, (Float) value); } else if (value instanceof Double) { compiled.setDouble(key, (Double) value); } else if (value instanceof BigDecimal) { compiled.setBigDecimal(key, (BigDecimal) value); } else if (value instanceof Short) { compiled.setShort(key, (Short) value); } else if (value instanceof BigInteger) { compiled.setBigInteger(key, (BigInteger) value); } else if (value instanceof Character) { compiled.setCharacter(key, (Character) value); } else { compiled.setParameter(key, value); }//from www . j av a2 s.c o m } final List result = compiled.list(); LinkedHashSet<ContentKey> distinctContentKeySet = new LinkedHashSet<ContentKey>(result.size()); for (Object value : result) { if (value instanceof ContentKey) { distinctContentKeySet.add((ContentKey) value); } else { Object[] valueList = (Object[]) value; distinctContentKeySet.add(((ContentKey) valueList[0])); } } List<ContentKey> distinctContentKeyList = new ArrayList<ContentKey>(distinctContentKeySet.size()); distinctContentKeyList.addAll(distinctContentKeySet); return distinctContentKeyList; } }); }
From source file:com.mimp.hibernate.HiberFamilia.java
public ArrayList<Taller> listaTalleresHabilitados() { Session session = sessionFactory.getCurrentSession(); session.beginTransaction();//from w ww . ja v a 2 s. c o m String hql = "From Taller T WHERE T.habilitado = :hab order by T.id"; Query query = session.createQuery(hql); query.setShort("hab", Short.parseShort("0")); List talleres = query.list(); ArrayList<Taller> allTalleres = new ArrayList(); for (Iterator iter = talleres.iterator(); iter.hasNext();) { Taller temp = (Taller) iter.next(); allTalleres.add(temp); } return allTalleres; }
From source file:com.mimp.hibernate.HiberFamilia.java
public ArrayList<Taller> listaTalleresHabilitadosPorDep(String ua) { Session session = sessionFactory.getCurrentSession(); session.beginTransaction();/*from w ww. j a v a 2 s . c o m*/ String hql = "From Taller T WHERE T.habilitado = :hab and T.unidad = :ua order by T.id asc"; Query query = session.createQuery(hql); query.setShort("hab", Short.parseShort("0")); query.setString("ua", ua); List talleres = query.list(); ArrayList<Taller> allTalleres = new ArrayList(); for (Iterator iter = talleres.iterator(); iter.hasNext();) { Taller temp = (Taller) iter.next(); allTalleres.add(temp); } return allTalleres; }
From source file:com.mimp.hibernate.HiberMain.java
public ArrayList<Designacion> getListaDesignacionesAdoptantesExtranjero(long idExp) { Session session = sessionFactory.getCurrentSession(); session.beginTransaction();//ww w .j a v a 2 s . c o m String hql = "From Designacion D where D.expedienteFamilia = :idExp and D.aceptacionConsejo = :aceptacion and D.tipoPropuesta = :tipo order by D.fechaConsejo DESC"; Query query = session.createQuery(hql); query.setLong("idExp", idExp); query.setShort("aceptacion", Short.parseShort("4")); query.setString("tipo", "extranjero"); List designaciones = query.list(); ArrayList<Designacion> allDesignaciones = new ArrayList(); for (Iterator iter = designaciones.iterator(); iter.hasNext();) { Designacion temp = (Designacion) iter.next(); Hibernate.initialize(temp.getNna()); allDesignaciones.add(temp); } return allDesignaciones; }
From source file:com.qcadoo.model.internal.search.SearchQueryImpl.java
License:Open Source License
@Override public void addParameters(final Query query) { for (Map.Entry<String, String> parameter : strings.entrySet()) { query.setString(parameter.getKey(), parameter.getValue()); }/*from ww w. j a va 2 s . c om*/ for (Map.Entry<String, Boolean> parameter : booleans.entrySet()) { query.setBoolean(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Byte> parameter : bytes.entrySet()) { query.setByte(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Short> parameter : shorts.entrySet()) { query.setShort(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Integer> parameter : integers.entrySet()) { query.setInteger(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Long> parameter : longs.entrySet()) { query.setLong(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Float> parameter : floats.entrySet()) { query.setFloat(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Double> parameter : doubles.entrySet()) { query.setDouble(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, BigDecimal> parameter : bigDecimals.entrySet()) { query.setBigDecimal(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Date> parameter : dates.entrySet()) { query.setDate(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Date> parameter : times.entrySet()) { query.setTime(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Date> parameter : timestamps.entrySet()) { query.setTimestamp(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Object> parameter : parameters.entrySet()) { query.setParameter(parameter.getKey(), parameter.getValue()); } for (Map.Entry<String, Collection<? extends Object>> parametersList : parameterLists.entrySet()) { query.setParameterList(parametersList.getKey(), parametersList.getValue()); } for (Map.Entry<String, Object> parameter : entities.entrySet()) { query.setEntity(parameter.getKey(), parameter.getValue()); } }
From source file:de.fhg.fokus.hss.db.op.IMPI_IMPU_DAO.java
License:Open Source License
public static List get_all_IMPU_of_IMSU_with_User_State(Session session, int id_imsu, short user_state) { Query query; query = session.createSQLQuery("select * from impi_impu" + " inner join impi on impi_impu.id_impi=impi.id" + " inner join impu on impi_impu.id_impu=impu.id" + " where impi.id_imsu=? and impu.user_state=?").addEntity(IMPU.class); query.setInteger(0, id_imsu);/*from w w w . j a v a 2s. c o m*/ query.setShort(1, user_state); return query.list(); }
From source file:gcom.atendimentopublico.RepositorioAtendimentoPublicoHBM.java
License:Open Source License
/** * //from ww w . ja v a 2s.c o m * * @author Arthur Carvalho * @date 19/06/2010 * @param obterValorDebitoHelper * @return o valor do dbito * @throws ErroRepositorioException */ public BigDecimal obterValorDebitoHidrometroCapacidade(ObterValorDebitoHelper params) throws ErroRepositorioException { Session session = HibernateUtil.getSession(); String consulta; BigDecimal retornoConsulta = null; Query query = null; try { consulta = "SELECT scv.valor " + "FROM ServicoCobrancaValor scv " + "where scv.servicoTipo.id = :servicoTipoId " + "and scv.imovelPerfil.id = :imovelPerfilId " + "and scv.dataVigenciaInicial <= :dataAtual " + "and scv.dataVigenciaFinal >= :dataAtual "; if (params.getSituacaoMedicao() != null) { consulta += "and scv.indicadorMedido = :situacaoMedicao "; } if (params.getHidrometroCapacidade() != null) { consulta += "and scv.hidrometroCapacidade.id = :hidrometroCapacidadeId "; } consulta += " ORDER BY scv.dataVigenciaFinal DESC "; query = session.createQuery(consulta).setInteger("imovelPerfilId", params.getImovelPerfil().getId()) .setInteger("servicoTipoId", params.getServicoTipo().getId()).setDate("dataAtual", new Date()); if (params.getSituacaoMedicao() != null) { query.setShort("situacaoMedicao", params.getSituacaoMedicao()); } if (params.getHidrometroCapacidade() != null) { query.setInteger("hidrometroCapacidadeId", params.getHidrometroCapacidade().getId()); } retornoConsulta = (BigDecimal) query.setMaxResults(1).uniqueResult(); if (retornoConsulta == null) { consulta = "SELECT scv.valor " + "FROM ServicoCobrancaValor scv " + "where scv.servicoTipo.id = :servicoTipoId " + "and scv.imovelPerfil.id = :imovelPerfilId " + "and scv.dataVigenciaInicial <= :dataAtual " + "and scv.dataVigenciaFinal >= :dataAtual "; if (params.getSituacaoMedicao() != null) { consulta += "and scv.indicadorMedido = :situacaoMedicao "; } consulta += " ORDER BY scv.dataVigenciaFinal DESC "; query = session.createQuery(consulta).setInteger("imovelPerfilId", params.getImovelPerfil().getId()) .setInteger("servicoTipoId", params.getServicoTipo().getId()) .setDate("dataAtual", new Date()); if (params.getSituacaoMedicao() != null) { query.setShort("situacaoMedicao", params.getSituacaoMedicao()); } retornoConsulta = (BigDecimal) query.setMaxResults(1).uniqueResult(); if (retornoConsulta == null) { consulta = "SELECT scv.valor " + "FROM ServicoCobrancaValor scv " + "where scv.servicoTipo.id = :servicoTipoId " + "and scv.dataVigenciaInicial <= :dataAtual " + "and scv.dataVigenciaFinal >= :dataAtual "; if (params.getSituacaoMedicao() != null) { consulta += "and scv.indicadorMedido = :situacaoMedicao "; } if (params.getHidrometroCapacidade() != null) { consulta += "and scv.hidrometroCapacidade.id = :hidrometroCapacidadeId "; } consulta += " ORDER BY scv.dataVigenciaFinal DESC "; query = session.createQuery(consulta) .setInteger("servicoTipoId", params.getServicoTipo().getId()) .setDate("dataAtual", new Date()); if (params.getSituacaoMedicao() != null) { query.setShort("situacaoMedicao", params.getSituacaoMedicao()); } if (params.getHidrometroCapacidade() != null) { query.setInteger("hidrometroCapacidadeId", params.getHidrometroCapacidade().getId()); } retornoConsulta = (BigDecimal) query.setMaxResults(1).uniqueResult(); if (retornoConsulta == null) { consulta = "SELECT st.valor " + "FROM ServicoTipo st " + "where st.id = :servicoTipoId "; retornoConsulta = (BigDecimal) session.createQuery(consulta) .setInteger("servicoTipoId", params.getServicoTipo().getId()).setMaxResults(1) .uniqueResult(); } } } } catch (HibernateException e) { e.printStackTrace(); throw new ErroRepositorioException("Erro no Hibernate"); } finally { HibernateUtil.closeSession(session); } return retornoConsulta; }
From source file:gcom.atendimentopublico.RepositorioAtendimentoPublicoHBM.java
License:Open Source License
/** * [UC1056] Gerar Relatrio de Acompanhamento dos Registros de Atendimento * /*from ww w. j a v a 2s. co m*/ * @author Hugo Leonardo, Diogo Peixoto * @date 28/09/2010, 26/04/2011 * * @param FiltrarAcompanhamentoRegistroAtendimentoHelper * @return Collection * @throws ErroRepositorioException */ public Collection pesquisarRelatorioAcompanhamentoRAAnalitico( FiltrarAcompanhamentoRegistroAtendimentoHelper helper) throws ErroRepositorioException { Collection retorno = null; String consulta = ""; Query query = null; Session session = HibernateUtil.getSession(); String groupByMunicipio = ""; String orderBy = " rau.unidadeOrganizacional "; if (!Util.isVazioOrNulo(helper.getMunicipiosAssociados())) { groupByMunicipio = " GROUP BY munRA.nome, munRA.id, rau.unidadeOrganizacional.id, step.descricao, ra.registroAtendimento, " + " ra.dataEncerramento, ra.dataEncerramento, ame.descricao, rau.unidadeOrganizacional.descricao, ame.id, ra.id "; orderBy = " munRA.nome "; } try { consulta += this.montarSelectRelatorioAcompanhamentoAnalitico(helper) + this.montarFromRelatorioAcompanhamentoAnalitico(helper) + " where ra.unidadeAtual = uni.id and "; if (Util.verificarNaoVazio(helper.getIdUnidadeAtendimento())) { consulta += " rau.unidadeOrganizacional = :unidade and " + " rau.atendimentoRelacaoTipo = 1 and "; } if (!Util.isVazioOrNulo(helper.getMunicipiosAssociados())) { consulta += " (munRA.id IN (:municipios) or munImo.id IN (:municipios)) and "; } if (!Util.isVazioOrNulo(helper.getIdsMotivoEncerramentoSelecionados())) { consulta += " ame.id in (:motivo) and "; } if (helper.getPeriodoAtendimentoInicial() != null && helper.getPeriodoAtendimentoFinal() != null) { consulta += " (ra.registroAtendimento between :dtAtendimentoIncial and :dtAtendimentoFinal) and "; } if (helper.getPeriodoEncerramentoInicial() != null && helper.getPeriodoEncerramentoFinal() != null) { consulta += " (ra.dataEncerramento between :dtEncerramentoIncial and :dtEncerramentoFinal) and "; } if (Util.verificarNaoVazio(helper.getSituacaoRA())) { consulta += " ra.codigoSituacao = :situacao and "; } if (Util.verificarNaoVazio(helper.getSituacaoRA()) && helper.getSituacaoRA().equals("0") && Util.verificarNaoVazio(helper.getSituacaoRAAbertos()) && helper.getSituacaoRAAbertos().equals("1")) { consulta += " (ra.dataPrevistaAtual >= :dtCorrente " + " or ra.dataPrevistaOriginal >= :dtCorrente) and "; } else if (Util.verificarNaoVazio(helper.getSituacaoRA()) && helper.getSituacaoRA().equals("0") && Util.verificarNaoVazio(helper.getSituacaoRAAbertos()) && helper.getSituacaoRAAbertos().equals("0")) { consulta += " (ra.dataPrevistaAtual < :dtCorrente " + " or ra.dataPrevistaOriginal < :dtCorrente) and "; } // remove o ltimo AND consulta = Util.removerUltimosCaracteres(consulta, 4); consulta += groupByMunicipio; consulta += " ORDER BY " + orderBy; query = (Query) session.createQuery(consulta); if (Util.verificarNaoVazio(helper.getIdUnidadeAtendimento())) { query.setString("unidade", helper.getIdUnidadeAtendimento().toString()); } if (!Util.isVazioOrNulo(helper.getMunicipiosAssociados())) { query.setParameterList("municipios", helper.getMunicipiosAssociados()); } if (!Util.isVazioOrNulo(helper.getIdsMotivoEncerramentoSelecionados())) { query.setParameterList("motivo", helper.getIdsMotivoEncerramentoSelecionados()); } if (helper.getPeriodoAtendimentoInicial() != null && helper.getPeriodoAtendimentoFinal() != null) { query.setDate("dtAtendimentoIncial", Util.formatarDataInicial(helper.getPeriodoAtendimentoInicial())); query.setDate("dtAtendimentoFinal", Util.formatarDataFinal(helper.getPeriodoAtendimentoFinal())); } if (helper.getPeriodoEncerramentoInicial() != null && helper.getPeriodoEncerramentoFinal() != null) { query.setDate("dtEncerramentoIncial", Util.formatarDataInicial(helper.getPeriodoEncerramentoInicial())); query.setDate("dtEncerramentoFinal", Util.formatarDataFinal(helper.getPeriodoEncerramentoFinal())); } if (Util.verificarNaoVazio(helper.getSituacaoRA()) && helper.getSituacaoRA().equals("0") && Util.verificarNaoVazio(helper.getSituacaoRAAbertos()) && (helper.getSituacaoRAAbertos().equals("0") || helper.getSituacaoRAAbertos().equals("1"))) { query.setDate("dtCorrente", new Date()); } if (Util.verificarNaoVazio(helper.getSituacaoRA()) && helper.getSituacaoRA().equals("0")) { query.setShort("situacao", RegistroAtendimento.SITUACAO_PENDENTE); } else if (Util.verificarNaoVazio(helper.getSituacaoRA()) && helper.getSituacaoRA().equals("1")) { query.setShort("situacao", RegistroAtendimento.SITUACAO_ENCERRADO); } retorno = query.list(); } catch (HibernateException e) { throw new ErroRepositorioException(e, "Erro no Hibernate"); } finally { HibernateUtil.closeSession(session); } return retorno; }
From source file:gcom.atendimentopublico.RepositorioAtendimentoPublicoHBM.java
License:Open Source License
/** * [UC1056] Gerar Relatrio de Acompanhamento dos Registros de Atendimento * /*from w w w.j av a 2 s. c o m*/ * @author Hugo Leonardo, Diogo Peixoto * @date 30/09/2010, 26/04/2011 * * @param FiltrarAcompanhamentoRegistroAtendimentoHelper * @return Integer * @throws ErroRepositorioException */ public Integer countPesquisarRelatorioAcompanhamentoRAAnalitico( FiltrarAcompanhamentoRegistroAtendimentoHelper helper) throws ErroRepositorioException { Integer retorno = 0; String consulta = ""; Query query = null; Session session = HibernateUtil.getSession(); try { consulta += " select count(distinct ra.id) " //0 + " from gcom.atendimentopublico.registroatendimento.RegistroAtendimento ra " + " inner join ra.solicitacaoTipoEspecificacao step " + " left join ra.atendimentoMotivoEncerramento ame "; consulta += " inner join ra.registroAtendimentoUnidades rau " + " inner join rau.unidadeOrganizacional uni " + " left join ra.localidade locRA " + " left join locRA.municipio munRA " + " left join ra.imovel imov " + " left join imov.localidade locImo " + " left join locImo.municipio munImo " + " where ra.unidadeAtual = uni.id and "; if (Util.verificarNaoVazio(helper.getIdUnidadeAtendimento())) { consulta += " rau.unidadeOrganizacional = :unidade and " + " rau.atendimentoRelacaoTipo = 1 and "; } if (!Util.isVazioOrNulo(helper.getMunicipiosAssociados())) { consulta += " (munRA.id IN (:municipios) or munImo.id IN (:municipios)) and "; } if (!Util.isVazioOrNulo(helper.getIdsMotivoEncerramentoSelecionados())) { consulta += " ame.id in (:motivo) and "; } if (helper.getPeriodoAtendimentoInicial() != null && helper.getPeriodoAtendimentoFinal() != null) { consulta += " (ra.registroAtendimento between :dtAtendimentoIncial and :dtAtendimentoFinal) and "; } if (helper.getPeriodoEncerramentoInicial() != null && helper.getPeriodoEncerramentoFinal() != null) { consulta += " (ra.dataEncerramento between :dtEncerramentoIncial and :dtEncerramentoFinal) and "; } if (Util.verificarNaoVazio(helper.getSituacaoRA())) { consulta += " ra.codigoSituacao = :situacao and "; } if (Util.verificarNaoVazio(helper.getSituacaoRA()) && helper.getSituacaoRA().equals("0") && Util.verificarNaoVazio(helper.getSituacaoRAAbertos()) && helper.getSituacaoRAAbertos().equals("1")) { consulta += " (ra.dataPrevistaAtual >= :dtCorrente " + " or ra.dataPrevistaOriginal >= :dtCorrente) and "; } else if (Util.verificarNaoVazio(helper.getSituacaoRA()) && helper.getSituacaoRA().equals("0") && Util.verificarNaoVazio(helper.getSituacaoRAAbertos()) && helper.getSituacaoRAAbertos().equals("0")) { consulta += " (ra.dataPrevistaAtual < :dtCorrente " + " or ra.dataPrevistaOriginal < :dtCorrente) and "; } // remove o ltimo AND consulta = Util.removerUltimosCaracteres(consulta, 4); query = (Query) session.createQuery(consulta); if (Util.verificarNaoVazio(helper.getIdUnidadeAtendimento())) { query.setString("unidade", helper.getIdUnidadeAtendimento().toString()); } if (!Util.isVazioOrNulo(helper.getMunicipiosAssociados())) { query.setParameterList("municipios", helper.getMunicipiosAssociados()); } if (!Util.isVazioOrNulo(helper.getIdsMotivoEncerramentoSelecionados())) { query.setParameterList("motivo", helper.getIdsMotivoEncerramentoSelecionados()); } if (helper.getPeriodoAtendimentoInicial() != null && helper.getPeriodoAtendimentoFinal() != null) { query.setDate("dtAtendimentoIncial", Util.formatarDataInicial(helper.getPeriodoAtendimentoInicial())); query.setDate("dtAtendimentoFinal", Util.formatarDataFinal(helper.getPeriodoAtendimentoFinal())); } if (helper.getPeriodoEncerramentoInicial() != null && helper.getPeriodoEncerramentoFinal() != null) { query.setDate("dtEncerramentoIncial", Util.formatarDataInicial(helper.getPeriodoEncerramentoInicial())); query.setDate("dtEncerramentoFinal", Util.formatarDataFinal(helper.getPeriodoEncerramentoFinal())); } if (Util.verificarNaoVazio(helper.getSituacaoRA()) && helper.getSituacaoRA().equals("0") && Util.verificarNaoVazio(helper.getSituacaoRAAbertos()) && (helper.getSituacaoRAAbertos().equals("0") || helper.getSituacaoRAAbertos().equals("1"))) { query.setDate("dtCorrente", new Date()); } if (Util.verificarNaoVazio(helper.getSituacaoRA()) && helper.getSituacaoRA().equals("0")) { query.setShort("situacao", RegistroAtendimento.SITUACAO_PENDENTE); } else if (Util.verificarNaoVazio(helper.getSituacaoRA()) && helper.getSituacaoRA().equals("1")) { query.setShort("situacao", RegistroAtendimento.SITUACAO_ENCERRADO); } retorno = (Integer) query.setMaxResults(1).uniqueResult(); } catch (HibernateException e) { throw new ErroRepositorioException(e, "Erro no Hibernate"); } finally { HibernateUtil.closeSession(session); } return retorno; }