Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node to traverse cannot be null (Hibernate SQL)

I'm performing a SQL query through hibernate, which looks like:

SELECT thi 
FROM track_history_items thi 
JOIN artists art 
  ON thi.artist_id = art.id 
WHERE thi.type = "TrackBroadcast" 
GROUP BY art.name 
ORDER thi.createdAt DESC

but I'm getting the message that 'Node to traverse cannot be null!'. Anyone know what could be causing this?

--EDIT--

I'm pretty sure that this problem is being caused by the possibility of artist_id to be null. However, I can't prevent this, so can I just skip the rows track_history_item rows which have a null artist_id?

like image 255
tiswas Avatar asked Apr 28 '11 11:04

tiswas


3 Answers

I have gotten that error only when using createQuery instead of createNamedQuery. So when detecting this, hibernate throws the exception.

Query query = entityManager.createQuery("DS.findUser");
like image 142
MariemJab Avatar answered Nov 06 '22 02:11

MariemJab


node to traverse cannot be null!

This is a generic Hibernate error message indicating a syntax problem in your query. As another example, forgetting to start a select clause with the word "SELECT" would yield the same error.

In this instance the syntax error is due to the on clause - HQL does not support them. Instead do a cross join like so:

FROM track_history_items thi, artists art 
WHERE thi.type = "TrackBroadcast" 
AND  thi.artist_id = art.id 
GROUP BY art.name 
ORDER thi.createdAt DESC
like image 33
Evan Oxfeld Avatar answered Nov 06 '22 02:11

Evan Oxfeld


I have come across this issue several times before as well and it has always been the case that the code was attempting to run a named query by calling createQuery instead of createNamedQuery, e.g. if you have a named query named "FIND_XXX" then the code would be calling entityManager.createQuery(FIND_XXX) which results in it trying to execute the String representing the name of the named query as if it was a standard dynamic query String (which is obviously a problem).

like image 22
brent777 Avatar answered Nov 06 '22 02:11

brent777