HHH-9969 - MySQLDialect handling of numeric cast targets is incorrect

This commit is contained in:
Steve Ebersole 2015-07-23 10:28:43 -05:00
parent 1f9b1c00f6
commit 11c76129bd
1 changed files with 37 additions and 3 deletions

View File

@ -30,6 +30,7 @@ import org.hibernate.hql.spi.id.local.AfterUseAction;
import org.hibernate.hql.spi.id.local.LocalTemporaryTableBulkIdStrategy; import org.hibernate.hql.spi.id.local.LocalTemporaryTableBulkIdStrategy;
import org.hibernate.internal.util.JdbcExceptionHelper; import org.hibernate.internal.util.JdbcExceptionHelper;
import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.StringHelper;
import org.hibernate.mapping.Column;
import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.StandardBasicTypes;
/** /**
@ -326,11 +327,13 @@ public class MySQLDialect extends Dialect {
case Types.INTEGER: case Types.INTEGER:
case Types.BIGINT: case Types.BIGINT:
case Types.SMALLINT: case Types.SMALLINT:
return "signed"; return smallIntegerCastTarget();
case Types.FLOAT: case Types.FLOAT:
case Types.REAL: {
return floatingPointNumberCastTarget();
}
case Types.NUMERIC: case Types.NUMERIC:
case Types.REAL: return fixedPointNumberCastTarget();
return "decimal";
case Types.VARCHAR: case Types.VARCHAR:
return "char"; return "char";
case Types.VARBINARY: case Types.VARBINARY:
@ -340,6 +343,37 @@ public class MySQLDialect extends Dialect {
} }
} }
/**
* Determine the cast target for {@link Types#INTEGER}, {@link Types#BIGINT} and {@link Types#SMALLINT}
*
* @return The proper cast target type.
*/
protected String smallIntegerCastTarget() {
return "signed";
}
/**
* Determine the cast target for {@link Types#FLOAT} and {@link Types#REAL} (DOUBLE)
*
* @return The proper cast target type.
*/
protected String floatingPointNumberCastTarget() {
// MySQL does not allow casting to DOUBLE nor FLOAT, so we have to cast these as DECIMAL.
// MariaDB does allow casting to DOUBLE, although not FLOAT.
return fixedPointNumberCastTarget();
}
/**
* Determine the cast target for {@link Types#NUMERIC}
*
* @return The proper cast target type.
*/
protected String fixedPointNumberCastTarget() {
// NOTE : the precision/scale are somewhat arbitrary choices, but MySQL/MariaDB
// effectively require *some* values
return "decimal(" + Column.DEFAULT_PRECISION + "," + Column.DEFAULT_SCALE + ")";
}
@Override @Override
public boolean supportsCurrentTimestampSelection() { public boolean supportsCurrentTimestampSelection() {
return true; return true;