{"id":3499,"date":"2014-03-27T04:51:05","date_gmt":"2014-03-27T04:51:05","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/27\/pass-variable-into-hibernate-criteria-collection-of-common-programming-errors\/"},"modified":"2014-03-27T04:51:05","modified_gmt":"2014-03-27T04:51:05","slug":"pass-variable-into-hibernate-criteria-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/27\/pass-variable-into-hibernate-criteria-collection-of-common-programming-errors\/","title":{"rendered":"Pass variable into hibernate criteria-Collection of common programming errors"},"content":{"rendered":"<p><code>Criteria crt = hibernateSession.createCriteria(Post.class);<\/code> <code>crt.add(Restrictions.eq(\"LogId\", new Integer(1234)));<\/code><\/p>\n<p>The query above has no trouble executing at all. But if changed the &#8220;new Integer(1234)&#8221; to a variable like below, the query returns a java.lang.NullPointerException error.<\/p>\n<p><code>int test = 1234;<\/code><br \/>\n<code>Criteria crt = hibernateSession.createCriteria(Post.class);<\/code> <code>crt.add(Restrictions.eq(\"LogId\", test));<\/code><\/p>\n<p>Anybody knows what is wrong here?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Criteria crt = hibernateSession.createCriteria(Post.class); crt.add(Restrictions.eq(&#8220;LogId&#8221;, new Integer(1234))); The query above has no trouble executing at all. But if changed the &#8220;new Integer(1234)&#8221; 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(&#8220;LogId&#8221;, test)); Anybody knows what is wrong here?<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3499","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3499","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3499"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3499\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3499"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}