GeekLondon.com Help icon Syndication Feed icon 

Node to traverse cannot be null!

More from the dumbass mistake department. Trying to boot up a Hibernate based project, I was getting this error:

java.lang.IllegalArgumentException: node to traverse cannot be null!

This was occurring during parsing of the named query information in the configuration. Eventually I tracked it down to this query:

@NamedQuery(
   name=Comment.COUNT_COMMENTS_BY_ARTICLE,
   query="count(*) from Comment where article = :article")

The problem was simply that I'd omitted a vital keyword from the query - because I'm normally retrieving lists of simple entities with queries of the form "from Foo where bar = :spong", which is quite legal, I failed to spot the missing select for ages even where it was staring me in the face! Here's that corrected query:

@NamedQuery(
   name=Comment.COUNT_COMMENTS_BY_ARTICLE,
   query="select count(*) from Comment where article = :article")

The moral of this story is perhaps that Hibernate's error handling isn't always very helpful, but a systematic approach to debugging will get you there in the end. In this case I did a binary search on the application's named queries until I found the offender, then it was relatively easy to spot the problem.

Posted at Dec 11, 2007 5:48:35 PM, and last updated Dec 11, 2007 5:52:08 PM
Section separator

Comments (3)

Anonymous  Nov 28, 2008 8:56:19 PM Thank you, I had the same problem!! just forget the 'select' keyword. lol
Anonymous  Dec 16, 2008 1:46:53 PM Very usefull comment. Thanks
Anonymous  Dec 23, 2008 2:12:33 AM You just saved me 5-20 minutes of crazy tedious debugging. Thanks.
Section separator

Add Comments