I am writing a hql query which retrieve details of perticular vehicle between given dates, I have a method like this.
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Session session = HibernateSession.getHibernateSession();
// Starting Transaction
Transaction transaction = session.beginTransaction();
String hql = null;
//ArrayList<HistoryLatitudeBean> vehicleHistoryList= new ArrayList<HistoryLatitudeBean>();
try {
DateFormat df = new SimpleDateFormat("yyyy/mm/dd");
Date frmDate= df.parse("2014/01/01");
Date toDate=df.parse("2014/09/01");
hql= "from HistoryLatitudeBean where vehicleno=:vehicleno and rdate BETWEEN :frmdate and :todate";
Query query =session.createQuery(hql);
query.setParameter("vehicleno", 12);
query.setParameter("frmdate", frmDate);
query.setParameter("todate", toDate);
List<HistoryLatitudeBean> groupList = (List<HistoryLatitudeBean>)query.list();
for(HistoryLatitudeBean arr : groupList){
System.out.println(arr.getLat());
}
transaction.commit();
}
catch(Exception e){
if (transaction!=null) transaction.rollback();
e.printStackTrace();
}
finally{session.close();}
}
Here is my bean class
@Entity
@Table(name="hlatlng")
public class HistoryLatitudeBean {
@Id
@Column(name="vehicleno")
private int vehicleno;
@Column(name="lat")
private String lat;
@Column(name="lng")
private String lng;
@Column(name="status")
private String status;
@Column(name="rdate")
private Date rdate;
@Column(name="rtime")
private Date rtime;
//getter and setters
}
The same query I am executing in mysql command line, I am getting 11 rows , but in java method I am getting no rows.
In Mysql db I am trying query as
select * from hlatlng where vehicleno=12 and rdate BETWEEN '2014/01/01' and '2014/09/01'
I am not getting how to pass the date formate through hibernate. whats wrong in my above method can any one tell me . It realy helps me.