1

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.

5
  • 1
    What does the stacktrace say? Commented May 6, 2014 at 17:08
  • The stack trace leads me from the second line of my controller to the create query line. @Reimeus Commented May 6, 2014 at 17:10
  • what parameters you trying insert? your query haven't any parameters Commented May 6, 2014 at 17:21
  • @AlekseiBulgak please read my note:"Note: this is not my full query, my full query is working and contains both parameters." Commented May 6, 2014 at 17:22
  • Is it possible to split up that long string of method calls into discrete calls? That might aid with debugging Commented May 6, 2014 at 17:45

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I did not want to share my full query, but I know for a fact that it works because it has worked and remains unchanged. I will try to debug for em, that may be the problem. Indeed, my entity manager is null.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.