我不知道为什么,但 hibernate 尝试将 BigDecimal 转换为我的列之一。该列在我的 DB2 数据库中定义为 Decimal(3,0)。所以不可能有 BigDecimal。
hbm.xml
<composite-id name="Id" class="db2.P5Id">
....
<key-property name="land" type="int">
<column name="PFIELD1" precision="3"/>
</key-property>
....
</composite-id>
当我尝试提交如下查询时
sf.createQuery("from P5 where type = 1 and land in (:cs)")
.setParameterList("cs", cses, Hibernate.INTEGER).list()
我收到 ClassCastException。提供的集合仅具有整数值。
最佳答案
这看起来像 this thread 中讨论的“问题”建议的修复解决方法是对DB2Dialect
进行子类化:
import org.hibernate.dialect.DB2Dialect;
import java.sql.Types;
public class FixedDB2Dialect extends DB2Dialect {
public FixedDB2Dialect() {
super();
registerColumnType(Types.INTEGER, "decimal($p)");
registerColumnType(Types.NUMERIC, "decimal($p,$s)");
registerColumnType(Types.DECIMAL, "decimal($p,$s)");
}
}
官方补丁可能存在 Jira 问题,但我找不到它。
关于java - Hibernate 使用 BigDecimal 而不是 Integer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2334428/