diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java index 732c58f269..33cc04437f 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java @@ -318,7 +318,13 @@ public class MySQLDialect extends Dialect { public String getCastTypeName(int code) { switch ( code ) { case Types.INTEGER: + case Types.BIGINT: + case Types.SMALLINT: return "signed"; + case Types.FLOAT: + case Types.NUMERIC: + case Types.REAL: + return "decimal"; case Types.VARCHAR: return "char"; case Types.VARBINARY: diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/ParameterTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/ParameterTest.java index 47d7dbc0f9..b95b621828 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/ParameterTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/ParameterTest.java @@ -23,8 +23,6 @@ */ package org.hibernate.jpa.test.criteria; -import static org.junit.Assert.assertEquals; - import javax.persistence.EntityManager; import javax.persistence.Parameter; import javax.persistence.TypedQuery; @@ -33,9 +31,12 @@ import javax.persistence.criteria.ParameterExpression; import javax.persistence.criteria.Path; import javax.persistence.criteria.Root; -import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; import org.junit.Test; +import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; + +import static org.junit.Assert.assertEquals; + /** * @author Steve Ebersole */ @@ -110,18 +111,16 @@ public class ParameterTest extends BaseEntityManagerFunctionalTestCase { .createQuery( MultiTypedBasicAttributesEntity.class ); criteria.from( MultiTypedBasicAttributesEntity.class ); - // Note: Use chars here -- MySQL restricts the types that can be used within cast to a really limited - // subset. Char is one of the few. criteria.where( - em.getCriteriaBuilder().in( em.getCriteriaBuilder().parameter( Character.class, "p1" ) ) - .value( em.getCriteriaBuilder().parameter( Character.class, "p2" ) ) - .value( em.getCriteriaBuilder().parameter( Character.class, "p3" ) ) + em.getCriteriaBuilder().in( em.getCriteriaBuilder().parameter( Long.class, "p1" ) ) + .value( em.getCriteriaBuilder().parameter( Long.class, "p2" ) ) + .value( em.getCriteriaBuilder().parameter( Long.class, "p3" ) ) ); TypedQuery query = em.createQuery( criteria ); - query.setParameter( "p1", 'a' ); - query.setParameter( "p2", 'b' ); - query.setParameter( "p3", 'c' ); + query.setParameter( "p1", 1L ); + query.setParameter( "p2", 2L ); + query.setParameter( "p3", 3L ); query.getResultList(); em.getTransaction().commit();