休眠返回BigDecimal数据类型,而不是long [英] hibernate returning BigDecimal datatype instead of long

查看:198
本文介绍了休眠返回BigDecimal数据类型,而不是long的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

休眠命名查询为数据类型为NUMBER的列返回BigDecimal.

The hibernate named query returns a BigDecimal for a column that has datatype NUMBER.

select col1 as "col1" from table1 union select col2 as "col1" from table2

在客户端,我希望col1的数据类型为long(原始) 我这样做:

On client side, I expect the datatype of col1 to be long (primitive) I do this:

<return-scalar column="col1" type="java.lang.Long" />

<return-scalar column="col1" type="long" />

在两种情况下,我都会得到:

In both cases, I get :

java.lang.ClassCastException: java.math.BigDecimal incompatible with java.lang.Long

我该如何解决?我很怀疑,别名出现问题了吗?

How can I fix this? My suspiscion, something wrong with the aliasing?

推荐答案

默认情况下,Oracle NUMBER映射到Hibernate中的BigDecimal.尝试将类型设置为BigDecimal.

Oracle NUMBER maps to BigDecimal in Hibernate by default. Try setting the type to BigDecimal.

这篇关于休眠返回BigDecimal数据类型,而不是long的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆