// EJB3: COUNT returns Long
QueryTranslatorImpl translator = createNewQueryTranslator( "select count(*) from Human h" );
assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
assertEquals( "incorrect return type", Hibernate.LONG, translator.getReturnTypes()[0] );
translator = createNewQueryTranslator( "select count(h.height) from Human h" );
assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
assertEquals( "incorrect return type", Hibernate.LONG, translator.getReturnTypes()[0] );
// MAX, MIN return the type of the state-field to which they are applied.
translator = createNewQueryTranslator( "select max(h.height) from Human h" );
assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
assertEquals( "incorrect return type", Hibernate.DOUBLE, translator.getReturnTypes()[0] );
translator = createNewQueryTranslator( "select max(h.id) from Human h" );
assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
assertEquals( "incorrect return type", Hibernate.LONG, translator.getReturnTypes()[0] );
// AVG returns Double.
translator = createNewQueryTranslator( "select avg(h.height) from Human h" );
assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
assertEquals( "incorrect return type", Hibernate.DOUBLE, translator.getReturnTypes()[0] );
translator = createNewQueryTranslator( "select avg(h.id) from Human h" );
assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
assertEquals( "incorrect return type", Hibernate.DOUBLE, translator.getReturnTypes()[0] );
translator = createNewQueryTranslator( "select avg(h.bigIntegerValue) from Human h" );
assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
assertEquals( "incorrect return type", Hibernate.DOUBLE, translator.getReturnTypes()[0] );
// SUM returns Long when applied to state-fields of integral types (other than BigInteger);
translator = createNewQueryTranslator( "select sum(h.id) from Human h" );
assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
assertEquals( "incorrect return type", Hibernate.LONG, translator.getReturnTypes()[0] );
translator = createNewQueryTranslator( "select sum(h.intValue) from Human h" );
assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
assertEquals( "incorrect return type", Hibernate.LONG, translator.getReturnTypes()[0] );
// SUM returns Double when applied to state-fields of floating point types;
translator = createNewQueryTranslator( "select sum(h.height) from Human h" );
assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
assertEquals( "incorrect return type", Hibernate.DOUBLE, translator.getReturnTypes()[0] );
translator = createNewQueryTranslator( "select sum(h.floatValue) from Human h" );
assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
assertEquals( "incorrect return type", Hibernate.DOUBLE, translator.getReturnTypes()[0] );
// SUM returns BigInteger when applied to state-fields of type BigInteger
translator = createNewQueryTranslator( "select sum(h.bigIntegerValue) from Human h" );
assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
assertEquals( "incorrect return type", Hibernate.BIG_INTEGER, translator.getReturnTypes()[0] );
// SUM and BigDecimal when applied to state-fields of type BigDecimal.
translator = createNewQueryTranslator( "select sum(h.bigDecimalValue) from Human h" );
assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length );
assertEquals( "incorrect return type", Hibernate.BIG_DECIMAL, translator.getReturnTypes()[0] );
// special case to test classicquery special case handling of count(*)
QueryTranslator oldQueryTranslator = null;
String hql = "select count(*) from Human h";
QueryTranslatorFactory classic = new ClassicQueryTranslatorFactory();
oldQueryTranslator = classic.createQueryTranslator( hql, hql, Collections.EMPTY_MAP, getSessionFactoryImplementor() );
oldQueryTranslator.compile( Collections.EMPTY_MAP, true);
assertEquals( "incorrect return type count", 1, oldQueryTranslator.getReturnTypes().length );
assertEquals( "incorrect return type", Hibernate.LONG, oldQueryTranslator.getReturnTypes()[0] );