1

While trying to fetch Count(*) using Hibernate 5.4.17, the count value (from nativeQuery.uniqueResult() below) is being returned as java.time.Duration, when the same used to be returned as java.lang.Long with Hibernate 4.2.17.

Code:

@org.springframework.transaction.annotation.Transactional
    public int getResultCount(String queryString) {
        NativeQuery nativeQuery = this.getNativeSQLQuery(queryString);
        Object countObject = nativeQuery.uniqueResult();
        if (countObject instanceof BigInteger) {
            BigInteger obj = (BigInteger)countObject;
            return obj.intValue();
        } else {
            long count = (Long)countObject;
            return (int)count;
        }
    }

value of queryString -

SELECT COUNT(*) FROM Role role inner join ( SELECT rolePriv.role_id FROM role_privilege rolePriv WHERE rolePriv.permission IN ('user:view','user:edit') GROUP BY  rolePriv.role_id HAVING COUNT(distinct rolePriv.permission) = 2 ) rolePrivResult  on role.role_id=rolePrivResult.role_id where role.type = 0

Can someone please advise me what might be going incorrect, and where I should be looking at? I am not pasting the nativeQuery object value here as it is huge. Please let me if some specific field is needed or should be looked into.

Thanks!

Rohan Bhattacharya
  • 375
  • 1
  • 5
  • 13

0 Answers0