-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Problem fetching data between dates
PostPosted: Thu Feb 02, 2012 12:46 pm 
Newbie

Joined: Thu Jan 19, 2012 1:21 pm
Posts: 12
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;
    }


Top
 Profile  
 
 Post subject: Re: Problem fetching data between dates
PostPosted: Thu Feb 02, 2012 1:27 pm 
Newbie

Joined: Thu Jan 19, 2012 1:21 pm
Posts: 12
OOPS, actually, this does work - I was entering the wrong biDeviceId.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.