HHH-6748 : Test failures due to inconsistent numeric return type from native query
This commit is contained in:
parent
573910f5d9
commit
c5733e7837
|
@ -49,13 +49,21 @@ public class ColumnTransformerTest extends BaseCoreFunctionalTestCase {
|
||||||
s.flush();
|
s.flush();
|
||||||
|
|
||||||
// Test value conversion during insert
|
// Test value conversion during insert
|
||||||
Double heightViaSql = (Double)s.createSQLQuery("select size_in_cm from t_staff where t_staff.id=1").uniqueResult();
|
// Value returned by Oracle native query is a Types.NUMERIC, which is mapped to a BigDecimalType;
|
||||||
|
// Cast returned value to Number then call Number.doubleValue() so it works on all dialects.
|
||||||
|
double heightViaSql =
|
||||||
|
( (Number)s.createSQLQuery("select size_in_cm from t_staff where t_staff.id=1").uniqueResult() )
|
||||||
|
.doubleValue();
|
||||||
assertEquals(HEIGHT_CENTIMETERS, heightViaSql, 0.01d);
|
assertEquals(HEIGHT_CENTIMETERS, heightViaSql, 0.01d);
|
||||||
|
|
||||||
heightViaSql = (Double)s.createSQLQuery("select radiusS from t_staff where t_staff.id=1").uniqueResult();
|
heightViaSql =
|
||||||
|
( (Number)s.createSQLQuery("select radiusS from t_staff where t_staff.id=1").uniqueResult() )
|
||||||
|
.doubleValue();
|
||||||
assertEquals(HEIGHT_CENTIMETERS, heightViaSql, 0.01d);
|
assertEquals(HEIGHT_CENTIMETERS, heightViaSql, 0.01d);
|
||||||
|
|
||||||
heightViaSql = (Double)s.createSQLQuery("select diamet from t_staff where t_staff.id=1").uniqueResult();
|
heightViaSql =
|
||||||
|
( (Number)s.createSQLQuery("select diamet from t_staff where t_staff.id=1").uniqueResult() )
|
||||||
|
.doubleValue();
|
||||||
assertEquals(HEIGHT_CENTIMETERS*2, heightViaSql, 0.01d);
|
assertEquals(HEIGHT_CENTIMETERS*2, heightViaSql, 0.01d);
|
||||||
|
|
||||||
// Test projection
|
// Test projection
|
||||||
|
@ -78,7 +86,9 @@ public class ColumnTransformerTest extends BaseCoreFunctionalTestCase {
|
||||||
// Test update
|
// Test update
|
||||||
staff.setSizeInInches(1);
|
staff.setSizeInInches(1);
|
||||||
s.flush();
|
s.flush();
|
||||||
heightViaSql = (Double)s.createSQLQuery("select size_in_cm from t_staff where t_staff.id=1").uniqueResult();
|
heightViaSql =
|
||||||
|
( (Number)s.createSQLQuery("select size_in_cm from t_staff where t_staff.id=1").uniqueResult() )
|
||||||
|
.doubleValue();
|
||||||
assertEquals(2.54d, heightViaSql, 0.01d);
|
assertEquals(2.54d, heightViaSql, 0.01d);
|
||||||
s.delete(staff);
|
s.delete(staff);
|
||||||
t.commit();
|
t.commit();
|
||||||
|
|
|
@ -249,7 +249,11 @@ public class ComponentTest extends BaseCoreFunctionalTestCase {
|
||||||
s.flush();
|
s.flush();
|
||||||
|
|
||||||
// Test value conversion during insert
|
// Test value conversion during insert
|
||||||
Double heightViaSql = (Double)s.createSQLQuery("select height_centimeters from T_USER where T_USER.username='steve'").uniqueResult();
|
// Value returned by Oracle native query is a Types.NUMERIC, which is mapped to a BigDecimalType;
|
||||||
|
// Cast returned value to Number then call Number.doubleValue() so it works on all dialects.
|
||||||
|
Double heightViaSql =
|
||||||
|
( (Number)s.createSQLQuery("select height_centimeters from T_USER where T_USER.username='steve'").uniqueResult())
|
||||||
|
.doubleValue();
|
||||||
assertEquals(HEIGHT_CENTIMETERS, heightViaSql, 0.01d);
|
assertEquals(HEIGHT_CENTIMETERS, heightViaSql, 0.01d);
|
||||||
|
|
||||||
// Test projection
|
// Test projection
|
||||||
|
@ -272,7 +276,9 @@ public class ComponentTest extends BaseCoreFunctionalTestCase {
|
||||||
// Test update
|
// Test update
|
||||||
u.getPerson().setHeightInches(1);
|
u.getPerson().setHeightInches(1);
|
||||||
s.flush();
|
s.flush();
|
||||||
heightViaSql = (Double)s.createSQLQuery("select height_centimeters from T_USER where T_USER.username='steve'").uniqueResult();
|
heightViaSql =
|
||||||
|
( (Number)s.createSQLQuery("select height_centimeters from T_USER where T_USER.username='steve'").uniqueResult() )
|
||||||
|
.doubleValue();
|
||||||
assertEquals(2.54d, heightViaSql, 0.01d);
|
assertEquals(2.54d, heightViaSql, 0.01d);
|
||||||
s.delete(u);
|
s.delete(u);
|
||||||
t.commit();
|
t.commit();
|
||||||
|
|
|
@ -1446,7 +1446,9 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase {
|
||||||
s.persist( image );
|
s.persist( image );
|
||||||
s.flush();
|
s.flush();
|
||||||
|
|
||||||
Double sizeViaSql = (Double)s.createSQLQuery("select size_mb from image").uniqueResult();
|
// Value returned by Oracle is a Types.NUMERIC, which is mapped to a BigDecimalType;
|
||||||
|
// Cast returned value to Number then call Number.doubleValue() so it works on all dialects.
|
||||||
|
Double sizeViaSql = ( (Number)s.createSQLQuery("select size_mb from image").uniqueResult() ).doubleValue();
|
||||||
assertEquals(SIZE_IN_MB, sizeViaSql, 0.01d);
|
assertEquals(SIZE_IN_MB, sizeViaSql, 0.01d);
|
||||||
t.commit();
|
t.commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
@ -1459,7 +1461,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase {
|
||||||
s.update( image );
|
s.update( image );
|
||||||
s.flush();
|
s.flush();
|
||||||
|
|
||||||
sizeViaSql = (Double)s.createSQLQuery("select size_mb from image").uniqueResult();
|
sizeViaSql = ( (Number)s.createSQLQuery("select size_mb from image").uniqueResult() ).doubleValue();
|
||||||
assertEquals(NEW_SIZE_IN_MB, sizeViaSql, 0.01d);
|
assertEquals(NEW_SIZE_IN_MB, sizeViaSql, 0.01d);
|
||||||
|
|
||||||
s.delete(image);
|
s.delete(image);
|
||||||
|
|
|
@ -42,7 +42,11 @@ public class TestCustomColumnReadAndWrite extends AbstractExecutable {
|
||||||
t = s.beginTransaction();
|
t = s.beginTransaction();
|
||||||
|
|
||||||
// Check value conversion on insert
|
// Check value conversion on insert
|
||||||
Double sizeViaSql = (Double)s.createSQLQuery("select size_mb from documents").uniqueResult();
|
// Value returned by Oracle native query is a Types.NUMERIC, which is mapped to a BigDecimalType;
|
||||||
|
// Cast returned value to Number then call Number.doubleValue() so it works on all dialects.
|
||||||
|
Double sizeViaSql =
|
||||||
|
( (Number)s.createSQLQuery("select size_mb from documents").uniqueResult() )
|
||||||
|
.doubleValue();
|
||||||
assertEquals( SIZE_IN_MB, sizeViaSql, 0.01d );
|
assertEquals( SIZE_IN_MB, sizeViaSql, 0.01d );
|
||||||
|
|
||||||
// Test explicit fetch of all properties
|
// Test explicit fetch of all properties
|
||||||
|
|
|
@ -224,11 +224,17 @@ public class JoinedSubclassTest extends BaseCoreFunctionalTestCase {
|
||||||
s.flush();
|
s.flush();
|
||||||
|
|
||||||
// Test value conversion during insert
|
// Test value conversion during insert
|
||||||
Double heightViaSql = (Double)s.createSQLQuery("select height_centimeters from JPerson where name='Emmanuel'").uniqueResult();
|
// Value returned by Oracle native query is a Types.NUMERIC, which is mapped to a BigDecimalType;
|
||||||
|
// Cast returned value to Number then call Number.doubleValue() so it works on all dialects.
|
||||||
|
Double heightViaSql =
|
||||||
|
( (Number)s.createSQLQuery("select height_centimeters from JPerson where name='Emmanuel'").uniqueResult() )
|
||||||
|
.doubleValue();
|
||||||
assertEquals(HEIGHT_CENTIMETERS, heightViaSql, 0.01d);
|
assertEquals(HEIGHT_CENTIMETERS, heightViaSql, 0.01d);
|
||||||
Double expiryViaSql = (Double)s.createSQLQuery("select pwd_expiry_weeks from JEmployee where person_id=?")
|
Double expiryViaSql =
|
||||||
.setLong(0, e.getId())
|
( (Number)s.createSQLQuery("select pwd_expiry_weeks from JEmployee where person_id=?")
|
||||||
.uniqueResult();
|
.setLong(0, e.getId())
|
||||||
|
.uniqueResult()
|
||||||
|
).doubleValue();
|
||||||
assertEquals(PASSWORD_EXPIRY_WEEKS, expiryViaSql, 0.01d);
|
assertEquals(PASSWORD_EXPIRY_WEEKS, expiryViaSql, 0.01d);
|
||||||
|
|
||||||
// Test projection
|
// Test projection
|
||||||
|
@ -263,11 +269,15 @@ public class JoinedSubclassTest extends BaseCoreFunctionalTestCase {
|
||||||
p.setHeightInches(1);
|
p.setHeightInches(1);
|
||||||
e.setPasswordExpiryDays(7);
|
e.setPasswordExpiryDays(7);
|
||||||
s.flush();
|
s.flush();
|
||||||
heightViaSql = (Double)s.createSQLQuery("select height_centimeters from JPerson where name='Emmanuel'").uniqueResult();
|
heightViaSql =
|
||||||
|
( (Number)s.createSQLQuery("select height_centimeters from JPerson where name='Emmanuel'").uniqueResult() )
|
||||||
|
.doubleValue();
|
||||||
assertEquals(2.54d, heightViaSql, 0.01d);
|
assertEquals(2.54d, heightViaSql, 0.01d);
|
||||||
expiryViaSql = (Double)s.createSQLQuery("select pwd_expiry_weeks from JEmployee where person_id=?")
|
expiryViaSql =
|
||||||
.setLong(0, e.getId())
|
( (Number)s.createSQLQuery("select pwd_expiry_weeks from JEmployee where person_id=?")
|
||||||
.uniqueResult();
|
.setLong(0, e.getId())
|
||||||
|
.uniqueResult()
|
||||||
|
).doubleValue();
|
||||||
assertEquals(1d, expiryViaSql, 0.01d);
|
assertEquals(1d, expiryViaSql, 0.01d);
|
||||||
s.delete(p);
|
s.delete(p);
|
||||||
s.delete(e);
|
s.delete(e);
|
||||||
|
|
|
@ -109,9 +109,13 @@ public class SubselectTest extends BaseCoreFunctionalTestCase {
|
||||||
s.flush();
|
s.flush();
|
||||||
|
|
||||||
// Test value conversion during insert
|
// Test value conversion during insert
|
||||||
Double humanHeightViaSql = (Double)s.createSQLQuery("select height_centimeters from humans").uniqueResult();
|
// Value returned by Oracle native query is a Types.NUMERIC, which is mapped to a BigDecimalType;
|
||||||
|
// Cast returned value to Number then call Number.doubleValue() so it works on all dialects.
|
||||||
|
Double humanHeightViaSql =
|
||||||
|
( (Number)s.createSQLQuery("select height_centimeters from humans").uniqueResult() ).doubleValue();
|
||||||
assertEquals(HUMAN_CENTIMETERS, humanHeightViaSql, 0.01d);
|
assertEquals(HUMAN_CENTIMETERS, humanHeightViaSql, 0.01d);
|
||||||
Double alienHeightViaSql = (Double)s.createSQLQuery("select height_centimeters from aliens").uniqueResult();
|
Double alienHeightViaSql =
|
||||||
|
( (Number)s.createSQLQuery("select height_centimeters from aliens").uniqueResult() ).doubleValue();
|
||||||
assertEquals(ALIEN_CENTIMETERS, alienHeightViaSql, 0.01d);
|
assertEquals(ALIEN_CENTIMETERS, alienHeightViaSql, 0.01d);
|
||||||
s.clear();
|
s.clear();
|
||||||
|
|
||||||
|
|
|
@ -191,11 +191,16 @@ public class UnionSubclassTest extends BaseCoreFunctionalTestCase {
|
||||||
s.flush();
|
s.flush();
|
||||||
|
|
||||||
// Test value conversion during insert
|
// Test value conversion during insert
|
||||||
Double heightViaSql = (Double)s.createSQLQuery("select height_centimeters from UPerson where name='Emmanuel'").uniqueResult();
|
// Value returned by Oracle native query is a Types.NUMERIC, which is mapped to a BigDecimalType;
|
||||||
|
// Cast returned value to Number then call Number.doubleValue() so it works on all dialects.
|
||||||
|
Double heightViaSql =
|
||||||
|
( (Number)s.createSQLQuery("select height_centimeters from UPerson where name='Emmanuel'").uniqueResult() ).doubleValue();
|
||||||
assertEquals(HEIGHT_CENTIMETERS, heightViaSql, 0.01d);
|
assertEquals(HEIGHT_CENTIMETERS, heightViaSql, 0.01d);
|
||||||
Double expiryViaSql = (Double)s.createSQLQuery("select pwd_expiry_weeks from UEmployee where person_id=?")
|
Double expiryViaSql =
|
||||||
.setLong(0, e.getId())
|
( (Number)s.createSQLQuery("select pwd_expiry_weeks from UEmployee where person_id=?")
|
||||||
.uniqueResult();
|
.setLong(0, e.getId())
|
||||||
|
.uniqueResult()
|
||||||
|
).doubleValue();
|
||||||
assertEquals(PASSWORD_EXPIRY_WEEKS, expiryViaSql, 0.01d);
|
assertEquals(PASSWORD_EXPIRY_WEEKS, expiryViaSql, 0.01d);
|
||||||
|
|
||||||
// Test projection
|
// Test projection
|
||||||
|
@ -230,11 +235,15 @@ public class UnionSubclassTest extends BaseCoreFunctionalTestCase {
|
||||||
p.setHeightInches(1);
|
p.setHeightInches(1);
|
||||||
e.setPasswordExpiryDays(7);
|
e.setPasswordExpiryDays(7);
|
||||||
s.flush();
|
s.flush();
|
||||||
heightViaSql = (Double)s.createSQLQuery("select height_centimeters from UPerson where name='Emmanuel'").uniqueResult();
|
heightViaSql =
|
||||||
|
( (Number)s.createSQLQuery("select height_centimeters from UPerson where name='Emmanuel'").uniqueResult() )
|
||||||
|
.doubleValue();
|
||||||
assertEquals(2.54d, heightViaSql, 0.01d);
|
assertEquals(2.54d, heightViaSql, 0.01d);
|
||||||
expiryViaSql = (Double)s.createSQLQuery("select pwd_expiry_weeks from UEmployee where person_id=?")
|
expiryViaSql =
|
||||||
.setLong(0, e.getId())
|
( (Number)s.createSQLQuery("select pwd_expiry_weeks from UEmployee where person_id=?")
|
||||||
.uniqueResult();
|
.setLong(0, e.getId())
|
||||||
|
.uniqueResult()
|
||||||
|
).doubleValue();
|
||||||
assertEquals(1d, expiryViaSql, 0.01d);
|
assertEquals(1d, expiryViaSql, 0.01d);
|
||||||
s.delete(p);
|
s.delete(p);
|
||||||
s.delete(e);
|
s.delete(e);
|
||||||
|
|
Loading…
Reference in New Issue