What does addScalar do?

前端 未结 4 960
忘了有多久
忘了有多久 2020-12-14 06:37

The JavaDoc says:

SQLQuery org.hibernate.SQLQuery.addScalar(String columnAlias, Type type)

Declare a scalar query result

I know what

4条回答
  •  死守一世寂寞
    2020-12-14 07:31

    This is declaring that you want the result of the query to return objects for individual named columns, rather than entities. For instance

    createSQLQuery("SELECT COUNT(*) AS c FROM Users").addScalar("c").uniqueResult()
    

    Will return a single Long. If you specify multiple scalars, the result will come back as an array of Object. Its similar to executeScalar except that it works on named columns, and can return a composite result.

提交回复
热议问题