I have an issue where I am attempting to update a table that has a numeric column with a scale of 2 and the jdbc driver appears to be truncating the value. So '2.92' ends up as '2.00' in the database. Here is the environment I am running under: SQL Anywhere 11 with the latest EBF applied (EBF21751) JConnect 7.07 #5 (latest available) Hibernate 4.1.11 Spring 3.2.4 The numeric column in my database is defined as numeric(11,2). The variable in the hibernate entity for the column is mapped as a BigDecimal. When using an older JConnect 6.0 jdbc driver this problem did not occur (had to upgrade because of a timestamp bug in old 6.0 jdbc driver). Changing the variable type to a Double solves the problem, but is not an acceptable solution due to lack of precision for doubles. If this is a bug in the JConnect driver, does anyone know how I would go about submitting this as a bug - if it hasn't already. Thanks |
UPDATE I can now reproduce your issue, but only if my jConnect string does not include <property name="hibernate.connection.DYNAMIC_PREPARE">true</property> I can otherwise reproduce this behaviour with the following code: Java import java.sql.Connection; import java.sql.Driver; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.math.BigDecimal; import com.sybase.jdbc4.jdbc.*; public class jconnSelect { public static void main( String args[] ) { try { Connection con = DriverManager.getConnection("jdbc:sybase:Tds:localhost:2638?JCONNECT_VERSION=7", "DBA", "sql"); Statement stmt = con.createStatement(); stmt.executeUpdate("DROP TABLE t1"); stmt.executeUpdate("CREATE TABLE t1 ( c1 NUMERIC(11,2) )"); PreparedStatement pstmt = con.prepareStatement("INSERT INTO t1 (c1) VALUES (?)"); pstmt.setBigDecimal(1, new BigDecimal(2.92)); pstmt.executeUpdate(); ResultSet rs = stmt.executeQuery("SELECT c1 FROM t1"); while (rs.next()) { BigDecimal bd = rs.getBigDecimal(1); System.out.println("Value is: " + bd.toString()); } rs.close(); stmt.close(); con.close(); } catch (Exeception e){ e.printStackTrace(); } } } Result
Adding Result
|
I don't believe this is a jConnect Driver bug. I looks most likely this is a mapping issue in hibernate. You can open the hibernate sql trace to get more details about the sql executing. Another point is, when you upgrade jConnect jdbc, you need execute the sp SQL in the jconnect driver on the ASA server side to get the metadata consistent with it. The sp path is about: jConnect-707spsql_asa11.sql. I think. I did run the sql script that comes with JConnect as the documentation states. I also created a pure JDBC connection (not going through Hibernate) and binding a BigDecimal parameter still caused the truncation of the decimal portion. So I don't think this is a Hibernate issue. I will see if I am running the latest dialect just to be sure.
(16 Dec '13, 12:35)
tripperm
|
Are you using the latest Hibernate Dialect for SQL Anywhere 11 and Hibernate 4.x? (See: https://github.com/sqlanywhere/hibernate/tree/master/hibernate4 )
Please see the README: https://github.com/sqlanywhere/hibernate/blob/master/hibernate4/SQLAnywhereDialect_Readme_4.txt
jConnect Support Notes
Instead, these fields must be mapped as 'org.hibernate.type.StringType' types.
So:
would become: