HHH-6748 : Test failures due to inconsistent numeric return type from native query
This commit is contained in:
parent
4c41638202
commit
63ad1467fb
|
@ -116,8 +116,10 @@ public class CompositeElementTest extends BaseCoreFunctionalTestCase {
|
||||||
s.save( p );
|
s.save( p );
|
||||||
s.flush();
|
s.flush();
|
||||||
|
|
||||||
Integer sqlValue = (Integer) s.createSQLQuery("select child_position from ParentChild c where c.name='Child One'")
|
// Oracle returns BigDecimaal while other dialects return Integer;
|
||||||
.uniqueResult();
|
// casting to Number so it works on all dialects
|
||||||
|
Number sqlValue = ((Number) s.createSQLQuery("select child_position from ParentChild c where c.name='Child One'")
|
||||||
|
.uniqueResult());
|
||||||
assertEquals( 0, sqlValue.intValue() );
|
assertEquals( 0, sqlValue.intValue() );
|
||||||
|
|
||||||
Integer hqlValue = (Integer)s.createQuery("select c.position from Parent p join p.children c where p.name='Parent'")
|
Integer hqlValue = (Integer)s.createQuery("select c.position from Parent p join p.children c where p.name='Parent'")
|
||||||
|
@ -134,8 +136,8 @@ public class CompositeElementTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
c.setPosition( 2 );
|
c.setPosition( 2 );
|
||||||
s.flush();
|
s.flush();
|
||||||
sqlValue = (Integer) s.createSQLQuery("select child_position from ParentChild c where c.name='Child One'")
|
sqlValue = ( (Number) s.createSQLQuery("select child_position from ParentChild c where c.name='Child One'")
|
||||||
.uniqueResult();
|
.uniqueResult() );
|
||||||
assertEquals( 1, sqlValue.intValue() );
|
assertEquals( 1, sqlValue.intValue() );
|
||||||
s.delete( p );
|
s.delete( p );
|
||||||
t.commit();
|
t.commit();
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.join;
|
package org.hibernate.test.join;
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -181,12 +182,14 @@ public class JoinTest 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 person where name='Emmanuel'").uniqueResult();
|
// Oracle returns BigDecimaal while other dialects return Double;
|
||||||
assertEquals(HEIGHT_CENTIMETERS, heightViaSql, 0.01d);
|
// casting to Number so it works on all dialects
|
||||||
Double expiryViaSql = (Double)s.createSQLQuery("select pwd_expiry_weeks from t_user where person_id=?")
|
Number heightViaSql = (Number)s.createSQLQuery("select height_centimeters from person where name='Emmanuel'").uniqueResult();
|
||||||
|
assertEquals(HEIGHT_CENTIMETERS, heightViaSql.doubleValue(), 0.01d);
|
||||||
|
Number expiryViaSql = (Number)s.createSQLQuery("select pwd_expiry_weeks from t_user where person_id=?")
|
||||||
.setLong(0, u.getId())
|
.setLong(0, u.getId())
|
||||||
.uniqueResult();
|
.uniqueResult();
|
||||||
assertEquals(PASSWORD_EXPIRY_WEEKS, expiryViaSql, 0.01d);
|
assertEquals(PASSWORD_EXPIRY_WEEKS, expiryViaSql.doubleValue(), 0.01d);
|
||||||
|
|
||||||
// Test projection
|
// Test projection
|
||||||
Double heightViaHql = (Double)s.createQuery("select p.heightInches from Person p where p.name = 'Emmanuel'").uniqueResult();
|
Double heightViaHql = (Double)s.createQuery("select p.heightInches from Person p where p.name = 'Emmanuel'").uniqueResult();
|
||||||
|
@ -220,12 +223,12 @@ public class JoinTest extends BaseCoreFunctionalTestCase {
|
||||||
p.setHeightInches(1);
|
p.setHeightInches(1);
|
||||||
u.setPasswordExpiryDays(7d);
|
u.setPasswordExpiryDays(7d);
|
||||||
s.flush();
|
s.flush();
|
||||||
heightViaSql = (Double)s.createSQLQuery("select height_centimeters from person where name='Emmanuel'").uniqueResult();
|
heightViaSql = (Number)s.createSQLQuery("select height_centimeters from person where name='Emmanuel'").uniqueResult();
|
||||||
assertEquals(2.54d, heightViaSql, 0.01d);
|
assertEquals(2.54d, heightViaSql.doubleValue(), 0.01d);
|
||||||
expiryViaSql = (Double)s.createSQLQuery("select pwd_expiry_weeks from t_user where person_id=?")
|
expiryViaSql = (Number)s.createSQLQuery("select pwd_expiry_weeks from t_user where person_id=?")
|
||||||
.setLong(0, u.getId())
|
.setLong(0, u.getId())
|
||||||
.uniqueResult();
|
.uniqueResult();
|
||||||
assertEquals(1d, expiryViaSql, 0.01d);
|
assertEquals(1d, expiryViaSql.doubleValue(), 0.01d);
|
||||||
|
|
||||||
s.delete(p);
|
s.delete(p);
|
||||||
s.delete(u);
|
s.delete(u);
|
||||||
|
|
Loading…
Reference in New Issue