oracle Hibernate.INTEGER 不可用,当 Hibernate 版本升级到 4.2.0.CR1
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14881775/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hibernate.INTEGER is unavailable, when the Hibernate version is upgraded to 4.2.0.CR1
提问by Tiny
I have just upgraded Hibernate from 3.2.5 to 4.2.0.CR1. I was using something like the following methods in DAO classes to locate the current row number in Oracle 10g with the createSQLQuery()
method.
我刚刚将 Hibernate 从 3.2.5 升级到4.2.0.CR1。我在 DAO 类中使用类似以下方法的方法来定位 Oracle 10g 中的当前行号createSQLQuery()
。
SELECT row_num
FROM (SELECT row_number()
OVER (
ORDER BY banner_id DESC) AS row_num,
banner_id
FROM banner_images
ORDER BY banner_id DESC)
WHERE banner_id = :id
@Override
@SuppressWarnings("unchecked")
public int getCurrentRow(String id, int rowsPerPage)
{
return (Integer) sessionFactory
.getCurrentSession()
.createSQLQuery("Above query")
.addScalar("row_num", Hibernate.INTEGER) //<------- ???
.setParameter("id", Long.parseLong(id))
.uniqueResult();
}
The .addScalar("row_num", Hibernate.INTEGER)
method as shown in the above code snippet, issues a compile-time error.
.addScalar("row_num", Hibernate.INTEGER)
上面代码片段中显示的方法会发出编译时错误。
cannot find symbol
symbol: variable INTEGER
location: class Hibernate
It is not available in the org.hibernate.Hibernate
class. The NetBeans IDE I'm using is 7.2.1 is not listing such a constant. Google search couldn't lead me to the actual solution. So what is the alternative in this version of Hibernate (4.2.0.CR1)?
它在org.hibernate.Hibernate
课堂上不可用。我使用的 NetBeans IDE 是 7.2.1 没有列出这样一个常量。谷歌搜索无法引导我找到实际的解决方案。那么这个版本的 Hibernate (4.2.0.CR1) 有什么替代方案呢?
回答by danny.lesnik
This Hinernate.Integer is deprecated since 3.6.x
此 Hinernate.Integer 自 3.6.x 起已弃用
You should use IntegerType.INSTANCE
instead.
你应该IntegerType.INSTANCE
改用。
回答by th3morg
If you are using an older version of Hibernate, but don't want to use a deprecated value while on 3.5.x or below, you'll have to use new IntegerType()
because IntegerType.INSTANCE
doesn't exist before 3.6.
如果您使用的是旧版本的 Hibernate,但不想在 3.5.x 或更低版本上使用已弃用的值,则必须使用,new IntegerType()
因为IntegerType.INSTANCE
在 3.6 之前不存在。
回答by better99
Do:
做:
- import org.hibernate.type.StandardBasicTypes;
- replace Hibernate.INTEGER by StandardBasicTypes.INTEGER.
- 导入 org.hibernate.type.StandardBasicTypes;
- 用 StandardBasicTypes.INTEGER 替换 Hibernate.INTEGER。