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.

Comments (1)

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