我使用OpenJPA和JTDS驱动程序将BigDecimal持久化到MS SQL Server。我已经像这样指定了列定义:
@Column(precision = 22, scale = 4)
private BigDecimal initialFee;
如果我删除表并让OpenJPA创建它,那么它在SQL server中看起来像这样:
Column_name Type Computed Length Prec Scale
initialFee numeric no 9 18 0
这是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>
如何指定SQL Server的比例和精度?
答案 0 :(得分:1)
我已经使用了:
@Column(columnDefinition="decimal(10,5)")
不是我希望的解决方案,因为我们在同一个项目中使用不同的DBMS,我希望避免兼容性问题,但它似乎适用于MSSQL,并且也适用于MySQL。