HHH-6748 : Test failures due to inconsistent return type from COUNT(*) in native query
This commit is contained in:
parent
5e668a039f
commit
3b3f921eb5
|
@ -33,6 +33,7 @@ import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
|
@ -47,10 +48,10 @@ public class JoinedSubclassAndSecondaryTable extends BaseCoreFunctionalTestCase
|
||||||
s.flush();
|
s.flush();
|
||||||
s.clear();
|
s.clear();
|
||||||
|
|
||||||
BigInteger rowCount = getTableRowCount( s );
|
long rowCount = getTableRowCount( s );
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"The address table is marked as optional. For null values no database row should be created",
|
"The address table is marked as optional. For null values no database row should be created",
|
||||||
BigInteger.valueOf( 0 ),
|
0,
|
||||||
rowCount
|
rowCount
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -68,7 +69,7 @@ public class JoinedSubclassAndSecondaryTable extends BaseCoreFunctionalTestCase
|
||||||
rowCount = getTableRowCount( s );
|
rowCount = getTableRowCount( s );
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Now we should have a row in the pool address table ",
|
"Now we should have a row in the pool address table ",
|
||||||
BigInteger.valueOf( 1 ),
|
1,
|
||||||
rowCount
|
rowCount
|
||||||
);
|
);
|
||||||
assertFalse( sp2.getAddress() == null );
|
assertFalse( sp2.getAddress() == null );
|
||||||
|
@ -78,8 +79,13 @@ public class JoinedSubclassAndSecondaryTable extends BaseCoreFunctionalTestCase
|
||||||
s.close();
|
s.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private BigInteger getTableRowCount(Session s) {
|
private long getTableRowCount(Session s) {
|
||||||
return (BigInteger) s.createSQLQuery( "select count(*) from POOL_ADDRESS" ).uniqueResult();
|
// the type returned for count(*) in a native query depends on the dialect
|
||||||
|
// Oracle returns Types.NUMERIC, which is mapped to BigDecimal;
|
||||||
|
// H2 returns Types.BIGINT, which is mapped to BigInteger;
|
||||||
|
Object retVal = s.createSQLQuery( "select count(*) from POOL_ADDRESS" ).uniqueResult();
|
||||||
|
assertTrue( Number.class.isInstance( retVal ) );
|
||||||
|
return ( ( Number ) retVal ).longValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue