An SQLQuery surrounded by brackets:
sessionFactory.getCurrentSession().createSQLQuery("(select * from MyTable)").list();
gives this NPE:
java.lang.NullPointerException
at org.hibernate.engine.jdbc.internal.BasicFormatterImpl$FormatProcess.isFunctionName(BasicFormatterImpl.java:376)
at org.hibernate.engine.jdbc.internal.BasicFormatterImpl$FormatProcess.openParen(BasicFormatterImpl.java:357)
at org.hibernate.engine.jdbc.internal.BasicFormatterImpl$FormatProcess.perform(BasicFormatterImpl.java:156)
at org.hibernate.engine.jdbc.internal.BasicFormatterImpl.format(BasicFormatterImpl.java:91)
at org.hibernate.engine.jdbc.spi.SqlStatementLogger.logStatement(SqlStatementLogger.java:101)
at org.hibernate.engine.jdbc.spi.SqlStatementLogger.logStatement(SqlStatementLogger.java:95)
BasicFormatterImpl line 155 contains:
else if ( "(".equals( token ) ) {
openParen();
}
The openParen function starts with this code:
private void openParen() {
if ( isFunctionName( lastToken )
...
}
The "(" bracket is the first token in the query, the lastToken is therefore null and calling the isFunctionName with a null value causes the NPE.
Known workaround: enclose the query with a 2nd select * from : select * from (select * from MyTable) as MyAlias.
FYI, the query we used contained a union of 2 tables : (select * from MyTable union select * from MyTableCopy) order by MyColumn, hence requiring the brackets.
|