我正在使用Hibernate,我编写了一个返回数组列表的方法,该查询应返回11个对象(行),但这里返回11个相同的对象(我的意思是11行相同)。 这是我的代码。
ArrayList<HistoryLatitudeBean> vehicleHistoryDetails = new ArrayList<HistoryLatitudeBean>();
vehicleHistoryDetails=FetchVehicleHistDetails.getVehicleHistory(selectedVehicle,frmDate,toDate);
getVehicleHistory()方法如下,
public static ArrayList<HistoryLatitudeBean> getVehicleHistory(String selectedVehicle, Date frmDate, Date toDate) {
Session session = HibernateSession.getHibernateSession();
// Starting Transaction
Transaction transaction = session.beginTransaction();
String hql = null;
ArrayList<HistoryLatitudeBean> vehicleHistoryList = new ArrayList<HistoryLatitudeBean>();
try {
hql="FROM HistoryLatitudeBean where vehicleno=:vehicleno and rdate BETWEEN :fromdate and :todate ";
Query query =session.createQuery(hql);
query.setParameter("vehicleno", 12);
query.setParameter("fromdate", frmDate);
query.setParameter("todate", toDate);
List<HistoryLatitudeBean> groupList = (List<HistoryLatitudeBean>)query.list();
//--->Here I checked through debug point , all object are same.
for(HistoryLatitudeBean arr : groupList){
vehicleHistoryList.add(arr);
}
transaction.commit();
} catch (Exception e) {
if (transaction!=null) transaction.rollback();
e.printStackTrace();
}
finally{
session.close();
}
return vehicleHistoryList;
}
任何人都可以告诉我。这对我很有帮助。谢谢。