Hello,
My app is executing a query wrote using the hibernate API for Java.
The query has a SELECT and it has a comparison: os.fecha <= :fechaFinal
os.fecha is a "datetime" in the database.
fechaFinal is a java.util.Date
The code is here:
Code:
public List<OrdenServicioConPaciente>
consultarOServConSaldoPendientes(Date fechaInicial, Date fechaFinal)
{
Session session = null ;
SessionFactory sessionFactory = null ;
Transaction tx = null ;
List result = null ;
Object[] datosFila = null ;
OrdenServicioConPaciente ordenServicioConPaciente = null ;
ArrayList<OrdenServicioConPaciente> listRetorno = null ;
try {
sessionFactory = HibernateUtil.getSessionFactory();
session = sessionFactory.getCurrentSession();
}
catch (java.lang.Exception exc) {
exc.printStackTrace();
}
tx = session.beginTransaction();
Query query =
session.createQuery("SELECT os.fecha, os.id, os.saldo, pac.tipoDocumento , pac.numDocumento, pac.primerNombre, pac.segundoNombre, pac.primerApellido, pac.segundoApellido FROM OrdenServicio os, Paciente pac WHERE os.saldo > 0.1 AND os.fechaPagoSaldoPaciente IS null AND os.fecha <= :fechaFinal AND os.pacientesId=pac.id ORDER BY os.fecha DESC");
// getByDocId.setDate("fechaInicial", fechaInicial );
query.setDate("fechaFinal" , fechaFinal );
result = (List)query.list();
When the final date (i.e. fechaFinal) is '2009-08-05 23:59:59' result has 62 elements.
When i execute the SQL sentence from MySQL Query Browser then 76 rows are fetched.
In particular, in java code there are 2 rows with FECHA column having values '2009-08-05 14:56:34' (first row) and '2009-08-05 14:37:30' (second row) that must be in the result list but they are not there. What is the problem ?
I'm working with MySQL Server v5.1
Any help or insight is really appreciated.
Ricardo De la Rosa