I'm new to Hibernate and need to query a table for values between two dates.
When I try the code below, I get an empty event list, even though the table contains events within the date range.
Can anyone explain what I am doing wrong?
Thanks.
Code:
    public List getEventTrxnByDeviceAndDateRange( long deviceId, Date startDate, Date endDate )
    {
        List<TbEventTrxn> list = null;
        try
        {
            org.hibernate.Transaction tx = session.beginTransaction();
            Query q = session.createQuery( "from TbEventTrxn where biDeviceId="+deviceId+" and dtTrxnTime between :startDate and :endDate" );
            q.setParameter( "startDate", startDate );
            q.setParameter( "endDate", endDate );
            System.out.println( "<DbHelper.getEventTrxnByDeviceAndDateRange> query = "+q.getQueryString());
            list = (List<TbEventTrxn>)q.list();
        }
        catch( Exception e )
        {
            e.printStackTrace();
        }
        return list;
    }
If I remove the date requirement, the following code works fine.
Code:
    public List getEventTrxnByDevice( long deviceId)
    {
        List<TbEventTrxn> list = null;
        try
        {
            org.hibernate.Transaction tx = session.beginTransaction();
            Query q = session.createQuery( "from TbEventTrxn where biDeviceId="+deviceId );
            list = (List<TbEventTrxn>)q.list();
        }
        catch( Exception e )
        {
            e.printStackTrace();
        }
        return list;
    }