[英]Native query causing null pointer exception
At this point I am very confused. 在这一点上我很困惑。 I have a controller that uses my DAO to run a query, but it is giving me a null pointer exception.
我有一个使用DAO来运行查询的控制器,但这给了我一个空指针异常。 I have been solving error after error but can't seem to get to the root of them all.
我一直在解决一个接一个的错误,但似乎无法理解所有错误的根源。
Controller: 控制器:
DAO d = new DAO();
List<objects> foo = d.callQuery(new object());
DAO: DAO:
Calendar cal = new GregorianCalendar();
cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
Date begin = new Date(cal.getTimeInMillis());
Date end = new Date(cal.getTimeInMillis());
String theQuery = "SELECT * from table1";
Query query = em.createNativeQuery(theQuery).setParameter("begin", begin).setParameter("end", end);
Error leads me to this line: Query query = em.createNativeQuery(theQuery).setParameter("begin", begin).setParameter("end", end);
错误将我引向此行:
Query query = em.createNativeQuery(theQuery).setParameter("begin", begin).setParameter("end", end);
What could possibly be null? 什么可能是空的? Note: this is not my full query, my full query is working and contains both parameters.
注意:这不是我的完整查询,我的完整查询正在运行,并且包含两个参数。
I printed begin
and end
and they both gave me the expected results. 我打印了
begin
和end
,它们都给了我预期的结果。 The stack trace leads me from the second line of my controller to the create query line. 堆栈跟踪将我从控制器的第二行引导到创建查询行。
I feel like I need more information, but trying to give you some clue: 我觉得我需要更多信息,但尝试向您提供一些线索:
I hope these questions can help. 希望这些问题能对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.