Pass variable into hibernate criteria-Collection of common programming errors
Criteria crt = hibernateSession.createCriteria(Post.class);
crt.add(Restrictions.eq("LogId", new Integer(1234)));
The query above has no trouble executing at all. But if changed the “new Integer(1234)” to a variable like below, the query returns a java.lang.NullPointerException error.
int test = 1234;
Criteria crt = hibernateSession.createCriteria(Post.class);
crt.add(Restrictions.eq("LogId", test));
Anybody knows what is wrong here?