diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractDB2Dictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractDB2Dictionary.java index b9b32bbff..99b56e760 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractDB2Dictionary.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractDB2Dictionary.java @@ -29,7 +29,10 @@ public abstract class AbstractDB2Dictionary public int varcharCastLength = 1000; public AbstractDB2Dictionary() { - numericTypeName = "DOUBLE"; + // http://publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp?topic=/com.ibm.db2.udb.apdv.java.doc + // /doc/rjvjdata.htm + // http://db.apache.org/derby/docs/10.3/ref/rrefsqlj12362.html + numericTypeName = "DECIMAL"; bitTypeName = "SMALLINT"; smallintTypeName = "SMALLINT"; tinyintTypeName = "SMALLINT"; @@ -69,6 +72,9 @@ public abstract class AbstractDB2Dictionary // the equivalent "X JOIN Y ON 1 = 1" crossJoinClause = "JOIN"; requiresConditionForCrossJoin = true; + + // DB2 / Derby allows precision to be set on a DECIMAL column. + fixedSizeTypeNameSet.remove("DECIMAL"); } public void indexOf(SQLBuffer buf, FilterValue str, FilterValue find, diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java index 093bd0228..5ed5346d5 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java @@ -145,6 +145,8 @@ public class MySQLDictionary "ZEROFILL" })); delimiter = "`"; + + fixedSizeTypeNameSet.remove("NUMERIC"); } public void connectedConfiguration(Connection conn) throws SQLException { diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestSQLBigDecimalId.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestSQLBigDecimalId.java index 1bc69ff21..cd90d92c9 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestSQLBigDecimalId.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/identity/TestSQLBigDecimalId.java @@ -24,10 +24,6 @@ import javax.persistence.EntityManager; import junit.textui.TestRunner; -import org.apache.openjpa.jdbc.conf.JDBCConfiguration; -import org.apache.openjpa.jdbc.sql.DBDictionary; -import org.apache.openjpa.jdbc.sql.MySQLDictionary; -import org.apache.openjpa.persistence.test.AllowFailure; import org.apache.openjpa.persistence.test.SingleEMFTestCase; /** @@ -48,18 +44,6 @@ public class TestSQLBigDecimalId e.setId(decimal); e.setData(1); - // trigger schema definition - JDBCConfiguration jdbccfg = (JDBCConfiguration) emf.getConfiguration(); - DBDictionary dict = jdbccfg.getDBDictionaryInstance(); - // currently BigDecimal is mapped to NUMERIC column type. This causes - // truncation error from MySQL. Without knowing the implication of changing the - // mapping of BigDecimal universally to DOUBLE, I will just change the mapping - // for this test case. - if (dict instanceof MySQLDictionary) { - dict.numericTypeName = "DOUBLE"; - } - - EntityManager em = emf.createEntityManager(); em.getTransaction().begin(); em.persist(e); @@ -74,7 +58,6 @@ public class TestSQLBigDecimalId } - @AllowFailure public void testQuery() { int data = 156; BigDecimal decimal = new BigDecimal(1234); @@ -91,6 +74,7 @@ public class TestSQLBigDecimalId (SQLBigDecimalIdEntity) em.createQuery("SELECT a FROM SQLBigDecimalIdEntity a WHERE a.data=" + data) .getSingleResult(); + // This would fail prior to OPENJPA-1224. assertEquals(e, e2); em.close();