When attempting to use a @NamedNativeQuery, hibernate appears to be attempting to get the results based on the automatic column alias' it typically generates for standard NamedQuery items.
Here is the made up code...
Code:
@NamedNativeQuery( name = "FindFields",
resultSetMapping = "FindFieldsResultSet",
query = "SELECT X.field1 FIELD1, Y.field2 FIELD2, Z.field3 FIELD3 from X, Y, Z ..." )
SQL Result set mapping
Code:
@SqlResultSetMapping( name = "FindFieldsResultSet", entities = {
@EntityResult( entityClass = X.class,
fields = { @FieldResult( name = "field1", column = "FIELD1" ) } ),
@EntityResult( entityClass = Y.class,
fields = { @FieldResult( name = "field2", column = "FIELD2" ) } ),
@EntityResult( entityClass = Z.class,
fields = { @FieldResult( name = "field3", column = "FIELD3" ) } ) } )
Code:
Query query = entityManager.createNamedQuery( "FindFields" );
List<Object[]> results = query.getResultList();
What I end up with on my query is:
ERROR JDBCExceptionReporter - Invalid argument: unknown column name X1_71_0_
Why is hibernate attempting to use column alias' that do not exist in the result set? Debugging, I see the query as my query above, however, when hibernate is trying to do a resultSet.getInt(name), name appears to be the X1_71_0_, NOT my defined alias! It fails at this point because those column alias' do not even exist.