Question

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. 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:

        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);

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. The stack trace leads me from the second line of my controller to the create query line.

Was it helpful?

Solution

I feel like I need more information, but trying to give you some clue:

  • How do you get the em object? Maybe em is null...
  • The query that you are using, is "SELECT * from table1"? I ask it because you are setting parameters to a query that doesn´t have parameters.

I hope these questions can help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top