[英]Why does this return null?
I sent the date value successfully. 我成功发送了日期值。 I checked from the 'Scoped Variables'.
我从“范围变量”中进行了检查。
This is a function in my bean that calls a function in helper: 这是我的bean中的一个函数,该函数在helper中调用一个函数:
public DataModel getFt() {
ftDataModel = new ListDataModel((List) fthelper.getByBeginDate(beginDate));
return ftDataModel;
}
This is the function that sent beginDate
to Hibernate. 这是将
beginDate
发送到Hibernate的函数。 But here it returns null. 但是在这里它返回null。 Why?
为什么?
public FinancialTransactions getByBeginDate(String beginDate){
List<FinancialTransactions> FtList = null;
try {
org.hibernate.Transaction tx = session.beginTransaction();
Query q = session.createQuery("from FinancialTransactions where DATE='" + beginDate + "'");
FtList = (List<FinancialTransactions>) q.list();
} catch (Exception e) {
e.printStackTrace();
}
return FtList.get(0);
}
One from these: 这些中的一个:
org.hibernate.Transaction tx = session.beginTransaction();
Query q = session.createQuery("from FinancialTransactions where DATE='" + beginDate + "'");
throw exception. 引发异常。 Use debugger or simple System.out... to find which of those two.
使用调试器或简单的System.out ...查找这两个。
You should use parameters in your query: 您应该在查询中使用参数:
Query q = session.createQuery("from FinancialTransactions where DATE=:date").setParameter("date",beginDate);
There should be no inner exception or else FtList.get(0) would result in exception also. 不应有内部异常,否则FtList.get(0)也会导致异常。
My guess is formating. 我的猜测是格式化。 You use string representation of dates.
您使用日期的字符串表示形式。 Always a bad idea since there are many things that can go wrong in convertions.
总是一个坏主意,因为在转换中有很多事情可能出错。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.