Dariusz on Software Quality

25/06/2010

SQL Error: 17006, SQLState: null Invalid column name in Hibernate

Filed under: en — Tags: , , — dariusz.cieslak @

Recently I’ve got the following error during SQL named query execution:

SQL Error: 17006, SQLState: null Invalid column name

In order to track the problem down I enabled SQL logging and collected SQL query issued, then run it under SQL monitor and … it was working without error! I was surprised.

In order to debug what’s going on I enabled detailed logging in Hibernate. What was happened then?

[INFO] could not read column value from result set: entityKey215_0_; Invalid column name

This message showed me that the problem was not related to generated SQL query but to column names expected by Hibernate. Generated recordset didn’t has entityKey215_0_ column. I added:

entityKey AS {list.entityKey}

to named SQL query and error dissapeared.

This error is not-very-obvious kind of error because Oracle hides column / table names in error messages returned. Why? I don’t get this cryptic error messages idea. In order to track an error under Oracle I had to enable verbose logging (error message standalone din’t give anything useful). Much simpler database MySQL has better error reporting than “fat” Oracle.

2 Comments »

  1. Could you talk deeper into the problem, such as the cause of it please? we don’t quite understand the solution you provided there, is “list” the table name?

    Thanks :)

    Comment by Anonymous — 18/02/2011 @

  2. “list” is an alias for object. {list.propertyName} will be translated by Hibernate to some mangled names in order to decode column values into object properties (an ORM job). The warning is visible when Hibernate fails to find value for some properties.

    Comment by dariusz.cieslak — 21/02/2011 @

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress