HHH-2917 - Using subselects as operands for arithmetic operations causes NullPointerException

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@20707 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Steve Ebersole 2010-09-25 16:27:09 +00:00
parent dbdcb01312
commit 636f728603
2 changed files with 23 additions and 5 deletions

View File

@ -579,11 +579,11 @@ expr
;
arithmeticExpr
: #(PLUS expr expr) { prepareArithmeticOperator( #arithmeticExpr ); }
| #(MINUS expr expr) { prepareArithmeticOperator( #arithmeticExpr ); }
| #(DIV expr expr) { prepareArithmeticOperator( #arithmeticExpr ); }
| #(MOD expr expr) { prepareArithmeticOperator( #arithmeticExpr ); }
| #(STAR expr expr) { prepareArithmeticOperator( #arithmeticExpr ); }
: #(PLUS exprOrSubquery exprOrSubquery) { prepareArithmeticOperator( #arithmeticExpr ); }
| #(MINUS exprOrSubquery exprOrSubquery) { prepareArithmeticOperator( #arithmeticExpr ); }
| #(DIV exprOrSubquery exprOrSubquery) { prepareArithmeticOperator( #arithmeticExpr ); }
| #(MOD exprOrSubquery exprOrSubquery) { prepareArithmeticOperator( #arithmeticExpr ); }
| #(STAR exprOrSubquery exprOrSubquery) { prepareArithmeticOperator( #arithmeticExpr ); }
// | #(CONCAT expr (expr)+ ) { prepareArithmeticOperator( #arithmeticExpr ); }
| #(UNARY_MINUS expr) { prepareArithmeticOperator( #arithmeticExpr ); }
| caseExpr

View File

@ -110,6 +110,24 @@ public class ASTParserLoadingTest extends FunctionalTestCase {
return new FunctionalTestClassTestSuite( ASTParserLoadingTest.class );
}
public void testSubSelectAsArtithmeticOperand() {
Session s = openSession();
s.beginTransaction();
// first a control
s.createQuery( "from Zoo z where ( select count(*) from Zoo ) = 0" ).list();
// now as operands singly:
s.createQuery( "from Zoo z where ( select count(*) from Zoo ) + 0 = 0" ).list();
s.createQuery( "from Zoo z where 0 + ( select count(*) from Zoo ) = 0" ).list();
// and doubly:
s.createQuery( "from Zoo z where ( select count(*) from Zoo ) + ( select count(*) from Zoo ) = 0" ).list();
s.getTransaction().commit();
s.close();
}
public void testJpaTypeOperator() {
// just checking syntax here...
Session s = openSession();