Criteria crt = hibernateSession.createCriteria(Post.class);
crt.add(Restrictions.eq("LogId", new Integer(1234)));
上面的查询完全没有问题。但是如果将“new Integer(1234)”更改为如下变量,则查询将返回java.lang.NullPointerException错误。
int test = 1234;
Criteria crt = hibernateSession.createCriteria(Post.class);
crt.add(Restrictions.eq("LogId", test));
有人知道这里有什么问题吗?
答案 0 :(得分:0)
最可能的解释是您正在使用java 1.4(或更早版本)运行时,它运行 not autobox原语。
Restrictions.eq()接受Object
是它的第二个参数,int
将在java 1.4之后自动装箱到Integer
个对象中。