HHH-8454 added numeric types to MySQLDialect#getCastTypeName

This commit is contained in:
Brett Meyer 2013-08-29 15:06:59 -04:00
parent a9e85716f1
commit 9f10ec5e74
2 changed files with 16 additions and 11 deletions

View File

@ -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:

View File

@ -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<MultiTypedBasicAttributesEntity> 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();