我的程序使用名为“Measurement Time”的DATETIME字段查询SQL数据库,下面是我的模型对象中的相关代码。我正在使用休眠。
private Timestamp measurementTime;
@Basic
@Column(name = "`Measurement Time`")
public Timestamp getMeasurementTime() {
return measurementTime;
}
public void setMeasurementTime(Timestamp measurementTime) {
this.measurementTime = measurementTime;
}
}
我在列表中选择了大约300,000行。当循环它们并按日期打印日期时:
System.out.println(obj.getMeasurementTime());
我得到了很多相同的日期时间,也许95%的日期时间是相同的。这与数据集不匹配。
我想知道这里可能出现什么问题,因为它似乎没有意义。持久性?驱动程序hibernate正在使用?
private List<ResultsEntity> getResults(){
Integer days ago = 365;
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_YEAR, - days_ago);
Timestamp oneYearAgo = new Timestamp(cal.getTimeInMillis());
System.out.println(days_ago + " days ago: "+ oneYearAgo);
List<ResultsEntity> ResultsEntityArrayList = new ArrayList<>();
DatabaseHelper databaseHelper = new DatabaseHelper();
Session session = databaseHelper.getSession();
Query query;
try{
query = session.createQuery(" from ResultsEntity where measurementTime > :time " +
"and transmissionStatus != :status " +
"and analyte like :analyteFilter and unit = :unit");
query.setParameter("time", oneYearAgo);
query.setParameter("status", "error");
query.setParameter("analyteFilter","Gel%");
query.setParameter("unit","m/L");
ResultsEntityArrayList = query.list();
}catch (Exception e){
System.out.println(e);
}
finally {
session.close();
}
return ResultsEntityArrayList;
}