Wednesday, September 11, 2013

Hibernate scalar types deprecated

In earlier versions of Hibernate, you might have had code that looks like this

session.createSQLQuery("select * from person").addScalar("id", Hibernate.INTEGER)


The fully qualified name of that type is org.hibernate.Hibernate.INTEGER.
That entire type class (org.hibernate.Hibernate) was replaced by org.hibernate.type.StandardBasicTypes.


Thus, your new code should look like this:

session.createSQLQuery("select * from person").addScalar("id", StandardBasicTypes.INTEGER)


Note that the documentation on the JBoss website is outdated depending on which version you are looking at.

For example, documentation for Hibernate 3.3 still says this:
sess.createSQLQuery("SELECT * FROM CATS")
 .addScalar("ID", Hibernate.LONG)