hibernate does not consider aliases when executing native SQL query
prblm: I am executing a native SQL query on MySQL with aliases, which I expect hibernate would use to fetch data out of resultset while transforming it into an object. But it throws SQLException due to column being fetched not found. It seems that hibernate is calling getXXX using the actual column name rather than alias. solution:While creating connection using jdbc, use useOldAliasMetadataBehavior=true description: As per JDBC specification result set interface should provide two methods getColumnName and getColumnLabel. But old MySQL JConnector versions provide only getColumnName method and which returns the column alias (or label). In Certain release (dont remember which one) they started providing both methods, but to keep backward compatibility they introduced a parameter "useOldAliasMetadataBehavior" which would make getColumnName return alias and all the existing applications would still work. Till JConnector release 5.1 default value for this option was true, thus we never faced the heat. When I upgrade to 5.1.x, default value has been set to false and hibernate still thinks that MySQL JConnector would return alias on getColumnName method call. The only work around till hibernates dialect incorporates this behavior it to explicitly setting option "useOldAliasMetadataBehavior=true".













