Search code examples
javasql-serveropenjpajtds

JTDS Ignoring OpenJPA scale annotation on BigDecimal


I am persisting BigDecimal to MS SQL Server using OpenJPA and the JTDS driver. I have specified the column definition like this:

@Column(precision = 22, scale = 4)
private BigDecimal initialFee;

If I drop the table and get OpenJPA to create it then it looks like this in SQL server:

Column_name Type       Computed     Length  Prec    Scale
initialFee  numeric    no           9       18      0    

Here is the persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="puOpenJPA_Core" transaction-type="JTA">
    <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
    <jta-data-source>java:jboss/datasources/Core</jta-data-source>
    <class>...</class>
    <properties>
      <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
      <property name="jboss.as.jpa.providerModule" value="org.apache.openjpa"/>
      <property name="openjpa.DynamicEnhancementAgent" value="false"/>
      <property name="openjpa.Log" value="File=stdout, DefaultLevel=WARN, Runtime=INFO, Tool=INFO, SQL=INFO"/>
      <property name="openjpa.jdbc.DBDictionary" value="org.apache.openjpa.jdbc.sql.SQLServerDictionary"/>
    </properties>
  </persistence-unit>
</persistence>

How can I specify the scale and precision for SQL server?


Solution

  • I have resorted to using:

    @Column(columnDefinition="decimal(10,5)")
    

    Not the solution I was hoping for as we use different DBMS with the same project and I was hoping to avoid compatibility problems, but it seems to work on MSSQL and should work on MySQL as well.