简体   繁体   中英

What's the source of this HQL query error?

    public List<UserDto> getTopUsersForDaysRankedByNumberOfQuestions(Integer daysCount, Integer usersCount) {
        return entityManager.createQuery(
                "select new com.javamentor.qa.platform.models.dto.UserDto(" +
                        "user.id, " +
                        "user.email, " +
                        "user.fullName, " +
                        "user.imageLink, " +
                        "user.city, " +
                        "(select sum(case when rep.count is null then 0 else rep.count end) " +
                        "from Reputation as rep where rep.author.id = user.id)), " +
                        "sum(case when vote.vote = 'UP_VOTE' then 1 when vote.vote = 'DOWN_VOTE' then - 1 else 0 end) as sumVotes, " +
                        "count(distinct answer.id) as answerCount " +
                        "from User as user " +
                        "inner join Answer as answer on answer.id = user.id " +
                        "left join VoteAnswer as vote on answer.id = vote.id " +
                        "where answer.persistDateTime > :date " +
                        "and answer.isDeleted = false " +
                        "and user.isDeleted = false " +
                        "group by user.id " +
                        "order by answerCount desc,sumVotes desc,user.id", UserDto.class)
                .setParameter("date", LocalDateTime.now().minusDays(daysCount))
                .setMaxResults(usersCount)
                .getResultList();
    }

So I have this method which should return List of UserDto but I'm getting the erorrs. Tried to fix this whole day but I still don't understand the source of these errors

o.h.hql.internal.ast.ErrorTracker        : line 1:299: unexpected token: ,
o.h.hql.internal.ast.ErrorTracker        : line 1:299: unexpected token: ,
o.h.hql.internal.ast.ErrorTracker        : line 1:392: expecting EOF, found ')'
o.h.hql.internal.ast.ErrorTracker        : line 1:392: expecting EOF, found ')'

Is this somehow syntax related or I'm doing something completely wrong?

Try doing a simple select dto from user, and if that works add the rest of the query sentence by sentence until you find the one that throws the error.

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