简体   繁体   English

当Hibernate版本升级到4.2.0.CR1时,Hibernate.INTEGER不可用

[英]Hibernate.INTEGER is unavailable, when the Hibernate version is upgraded to 4.2.0.CR1

I have just upgraded Hibernate from 3.2.5 to 4.2.0.CR1 . 我刚刚将Hibernate从3.2.5升级到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. 我在DAO类中使用类似以下方法的东西,使用createSQLQuery()方法在Oracle 10g中找到当前行号。

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. 它在org.hibernate.Hibernate类中不可用。 The NetBeans IDE I'm using is 7.2.1 is not listing such a constant. 我正在使用的NetBeans IDE是7.2.1未列出这样的常量。 Google search couldn't lead me to the actual solution. 谷歌搜索无法引导我找到实际的解决方案。 So what is the alternative in this version of Hibernate (4.2.0.CR1)? 那么在这个版本的Hibernate(4.2.0.CR1)中有什么替代方案呢?

This Hinernate.Integer is deprecated since 3.6.x 从3.6.x开始,不推荐使用此Hinernate.Integer

You should use IntegerType.INSTANCE instead. 您应该使用IntegerType.INSTANCE

如果您使用的是旧版本的Hibernate,但是在3.5.x或更低版本时不想使用已弃用的值,则必须使用new IntegerType()因为在3.6之前不存在IntegerType.INSTANCE

Do: 做:

  • import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.StandardBasicTypes;
  • replace Hibernate.INTEGER by StandardBasicTypes.INTEGER. 用StandardBasicTypes.INTEGER替换Hibernate.INTEGER。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 升级休眠版本会受到什么影响 - what will get affected if hibernate version is upgraded 带有Spring和Hibernate的Java应用程序从3.2.1升级到4.3.2以及从4.2.0升级到5.2.1引发错误 - Java application with Spring and Hibernate upgraded from 3.2.1 to 4.3.2 and 4.2.0 to 5.2.1 throwing error 如何在Wildfly 8.2中使用Hibernate Validator Jar的升级版本? - How to use an Upgraded Version of the Hibernate Validator Jar in Wildfly 8.2? 使用hibernate 4.2.0需要哪些库? - Which libraries are needed to use hibernate 4.2.0? Hibernate版本? - Hibernate version? 我将 hibernate-validator 升级到版本 6.1.5,应用程序在 WAS 8.5.5.17 上不起作用 - I upgraded hibernate-validator to version 6.1.5 and application doesn't work on WAS 8.5.5.17 Hibernate的未知实体升级到5.2.3及更高版本 - Unknown entity with Hibernate upgraded to 5.2.3 and above 在休眠状态下删除实体时是否检查版本? - Is version checked when we delete an entity in hibernate? 当添加到子级集合时,Hibernate @version不会递增 - Hibernate @version not incrementing when adding to collection of children JSR 303-休眠验证4.2.0-UnexpectedTypeException-@Valid和@Size组合 - JSR 303 - Hibernate Validation 4.2.0 - UnexpectedTypeException - @Valid and @Size in combination
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM