Pessoal boa noite… Desculpe a pergunta mas não consigo achar onde estou errando… estou iniciando com Hibernate e criteria to tentando converter uma sql para criteria e não acerto…
SELECT * FROM agendamentos M WHERE
(
(
( ( '2011-06-15 22:15' >= M.dataEHoraAgendamento ) AND ( '2011-06-15 22:15' < M.horarioEstimadoEntrega ) )
OR
( ( '2011-06-15 22:50' >= M.dataEHoraAgendamento ) AND ( '2011-06-15 22:50' < M.horarioEstimadoEntrega ) )
)
OR (
( ( '2011-06-15 22:15' <= M.dataEHoraAgendamento ) AND ( '2011-06-15 22:50' > M.horarioEstimadoEntrega ) )
)
)
tipo a sql acima to gerando assim
List<AgendamentoVO> lista = new ArrayList<AgendamentoVO>();
try {
this.sessao = HibernateUtil.getSessionFactory().openSession();
Criteria criteria = this.sessao.createCriteria(AgendamentoVO.class);
criteria.add(Restrictions.or(
Restrictions.or(
Restrictions.and(Restrictions.ge("dataEHoraAgendamento", DateHighLow.segundosLowValues(agendamentoVO.getDataEHoraAgendamento())),
Restrictions.lt("horarioEstimadoEntrega", DateHighLow.segundosHighValues(agendamentoVO.getHorarioEstimadoEntrega())))
,
Restrictions.and(Restrictions.ge("dataEHoraAgendamento", DateHighLow.segundosLowValues(agendamentoVO.getDataEHoraAgendamento())),
Restrictions.lt("horarioEstimadoEntrega", DateHighLow.segundosHighValues(agendamentoVO.getHorarioEstimadoEntrega())))
),
Restrictions.and(Restrictions.le("dataEHoraAgendamento", DateHighLow.segundosHighValues(agendamentoVO.getDataEHoraAgendamento())),
Restrictions.gt("horarioEstimadoEntrega", DateHighLow.segundosLowValues(agendamentoVO.getHorarioEstimadoEntrega())))
));
criteria.addOrder(Order.asc("dataEHoraAgendamento"));
lista = (ArrayList<AgendamentoVO>) criteria.list();
} catch (Exception e) {
e.printStackTrace();
lista = null;
} finally {
this.sessao.close();
}
no banco para teste tem 10 registros quando tento consultar ele duplica os registros … Qm puder ajudar muito obrigado …!! E desculpe se falei alguma bobeira …
Não sei o porque duplico o topico !!! ja ta respontido http://www.guj.com.br/java/244873-converter-sql-para-restrictions-resolvido