diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java index d6ba94f86..cb6ef998b 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java @@ -654,8 +654,18 @@ public abstract class MappingInfo // user-given specifics to override it int type = tmplate.getType(); int size = tmplate.getSize(); - if (type == Types.OTHER) - type = dict.getJDBCType(tmplate.getJavaType(), size == -1); + if (type == Types.OTHER) { + int precis = 0; + int scale = 0; + if(given != null) { + precis = given.getSize(); + scale = given.getDecimalDigits(); + } + type = + dict.getJDBCType(tmplate.getJavaType(), size == -1, precis, + scale); + } + boolean ttype = true; int otype = type; String typeName = tmplate.getTypeName(); diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java index fa4fce00f..095bc2b97 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java @@ -1479,12 +1479,21 @@ public class DBDictionary ///////// // Types ///////// - + /** * Return the preferred {@link Types} constant for the given * {@link JavaTypes} or {@link JavaSQLTypes} constant. */ public int getJDBCType(int metaTypeCode, boolean lob) { + return getJDBCType(metaTypeCode, lob, 0, 0); + } + + /** + * Return the preferred {@link Types} constant for the given + * {@link JavaTypes} or {@link JavaSQLTypes} constant. + */ + public int getJDBCType(int metaTypeCode, boolean lob, int precis, + int scale) { if (lob) { switch (metaTypeCode) { case JavaTypes.STRING: @@ -1510,10 +1519,20 @@ public class DBDictionary return getPreferredType(Types.CHAR); case JavaTypes.DOUBLE: case JavaTypes.DOUBLE_OBJ: - return getPreferredType(Types.DOUBLE); + if(precis > 0 || scale > 0) { + return getPreferredType(Types.NUMERIC); + } + else { + return getPreferredType(Types.DOUBLE); + } case JavaTypes.FLOAT: case JavaTypes.FLOAT_OBJ: - return getPreferredType(Types.REAL); + if(precis > 0 || scale > 0) { + return getPreferredType(Types.NUMERIC); + } + else { + return getPreferredType(Types.REAL); + } case JavaTypes.INT: case JavaTypes.INT_OBJ: return getPreferredType(Types.INTEGER); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/TestPrecisionMapping.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/TestPrecisionMapping.java index 64a9a5776..e1e3b1c66 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/TestPrecisionMapping.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/TestPrecisionMapping.java @@ -40,18 +40,18 @@ public class TestPrecisionMapping extends SingleEMFTestCase { testBigDecimalMapping("", Types.NUMERIC, 0, 0); } - public void testPrecisionOnly() { - // testDoubleMapping("Precis", Types.NUMERIC, 10, 0); + public void testPrecisionOnly() { + testDoubleMapping("Precis", Types.NUMERIC, 10, 0); testBigDecimalMapping("Precis", Types.NUMERIC, 10, 0); } - - public void testScaleOnly() { - // testDoubleMapping("Scale", Types.NUMERIC, 0 , 10); + + public void testScaleOnly() { + testDoubleMapping("Scale", Types.NUMERIC, 0, 10); testBigDecimalMapping("Scale", Types.NUMERIC, 0, 10); } public void testPrecisionAndScale() { -// testDoubleMapping("PrecisScale", Types.NUMERIC,10,10); + testDoubleMapping("PrecisScale", Types.NUMERIC,10,10); testBigDecimalMapping("PrecisScale", Types.NUMERIC, 10, 10); } @@ -83,5 +83,4 @@ public class TestPrecisionMapping extends SingleEMFTestCase { assertEquals(expectedScale, cols[0].getDecimalDigits()); } } - }