简体   繁体   中英

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 . I was using something like the following methods in DAO classes to locate the current row number in Oracle 10g with the createSQLQuery() method.

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.

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)?

This Hinernate.Integer is deprecated since 3.6.x

You should use IntegerType.INSTANCE instead.

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

Do:

  • import org.hibernate.type.StandardBasicTypes;
  • replace Hibernate.INTEGER by StandardBasicTypes.INTEGER.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM