HHH-16697 Fix auto type discovery for aggregate functions on Oracle
This commit is contained in:
parent
1a9732a5c2
commit
2fb7cdd08b
|
@ -715,7 +715,7 @@ public class OracleLegacyDialect extends Dialect {
|
||||||
}
|
}
|
||||||
//intentional fall-through:
|
//intentional fall-through:
|
||||||
case Types.DECIMAL:
|
case Types.DECIMAL:
|
||||||
if ( scale == 0 ) {
|
if ( scale == 0 && precision != 0 ) {
|
||||||
// Don't infer TINYINT or SMALLINT on Oracle, since the
|
// Don't infer TINYINT or SMALLINT on Oracle, since the
|
||||||
// range of values of a NUMBER(3,0) or NUMBER(5,0) just
|
// range of values of a NUMBER(3,0) or NUMBER(5,0) just
|
||||||
// doesn't really match naturally.
|
// doesn't really match naturally.
|
||||||
|
|
|
@ -767,7 +767,7 @@ public class OracleDialect extends Dialect {
|
||||||
}
|
}
|
||||||
//intentional fall-through:
|
//intentional fall-through:
|
||||||
case DECIMAL:
|
case DECIMAL:
|
||||||
if ( scale == 0 ) {
|
if ( scale == 0 && precision != 0 ) {
|
||||||
// Don't infer TINYINT or SMALLINT on Oracle, since the
|
// Don't infer TINYINT or SMALLINT on Oracle, since the
|
||||||
// range of values of a NUMBER(3,0) or NUMBER(5,0) just
|
// range of values of a NUMBER(3,0) or NUMBER(5,0) just
|
||||||
// doesn't really match naturally.
|
// doesn't really match naturally.
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.orm.test.procedure;
|
package org.hibernate.orm.test.procedure;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.sql.CallableStatement;
|
import java.sql.CallableStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
@ -187,11 +188,11 @@ public class OracleStoredProcedureTest {
|
||||||
public void testStoredProcedureReturnValue(EntityManagerFactoryScope scope) {
|
public void testStoredProcedureReturnValue(EntityManagerFactoryScope scope) {
|
||||||
scope.inTransaction(
|
scope.inTransaction(
|
||||||
entityManager -> {
|
entityManager -> {
|
||||||
Integer phoneCount = (Integer) entityManager
|
BigDecimal phoneCount = (BigDecimal) entityManager
|
||||||
.createNativeQuery( "SELECT fn_count_phones(:personId) FROM DUAL" )
|
.createNativeQuery( "SELECT fn_count_phones(:personId) FROM DUAL" )
|
||||||
.setParameter( "personId", person1.getId() )
|
.setParameter( "personId", person1.getId() )
|
||||||
.getSingleResult();
|
.getSingleResult();
|
||||||
assertEquals( 2, phoneCount );
|
assertEquals( BigDecimal.valueOf( 2 ), phoneCount );
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.orm.test.sql;
|
package org.hibernate.orm.test.sql;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
@ -227,11 +228,11 @@ public class OracleStoredProcedureTest {
|
||||||
@Test
|
@Test
|
||||||
public void testStoredProcedureReturnValue(EntityManagerFactoryScope scope) {
|
public void testStoredProcedureReturnValue(EntityManagerFactoryScope scope) {
|
||||||
scope.inTransaction( entityManager -> {
|
scope.inTransaction( entityManager -> {
|
||||||
Integer phoneCount = (Integer) entityManager
|
BigDecimal phoneCount = (BigDecimal) entityManager
|
||||||
.createNativeQuery( "SELECT fn_count_phones(:personId) FROM DUAL" )
|
.createNativeQuery( "SELECT fn_count_phones(:personId) FROM DUAL" )
|
||||||
.setParameter( "personId", 1 )
|
.setParameter( "personId", 1 )
|
||||||
.getSingleResult();
|
.getSingleResult();
|
||||||
assertEquals( 2, phoneCount );
|
assertEquals( BigDecimal.valueOf( 2L ), phoneCount );
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.orm.test.sql.autodiscovery;
|
package org.hibernate.orm.test.sql.autodiscovery;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
|
@ -20,6 +21,7 @@ import org.hibernate.engine.spi.SessionImplementor;
|
||||||
import org.hibernate.jdbc.Work;
|
import org.hibernate.jdbc.Work;
|
||||||
|
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
|
import org.hibernate.testing.orm.junit.JiraKey;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -137,4 +139,23 @@ public class AutoDiscoveryTest extends BaseCoreFunctionalTestCase {
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
session.close();
|
session.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@JiraKey( "HHH-16697" )
|
||||||
|
public void testAggregateQueryAutoDiscovery() {
|
||||||
|
Session session = openSession();
|
||||||
|
session.beginTransaction();
|
||||||
|
User u = new User( "steve" );
|
||||||
|
session.persist( u );
|
||||||
|
session.getTransaction().commit();
|
||||||
|
session.close();
|
||||||
|
|
||||||
|
session = openSession();
|
||||||
|
session.beginTransaction();
|
||||||
|
List<Object> result = session.createNativeQuery( "select sum(39.74) from t_user u" ).list();
|
||||||
|
Assert.assertEquals( new BigDecimal( "39.74" ), result.get( 0 ) );
|
||||||
|
session.remove( u );
|
||||||
|
session.getTransaction().commit();
|
||||||
|
session.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue