Ege Coskun
Ege Coskun

Reputation: 23

SQL Syntax error in Hibernate's map function

SELECT NEW Map (PRODUCT_CATEGORY, COUNT(PRODUCT_CATEGORY) AS COUNTER) from Product WHERE USER_ID = (SELECT USER_ID FROM USERS WHERE USERNAME='burak123'

Hi everyone, As hibernates document says here: https://docs.jboss.org/hibernate/orm/3.3/reference/en/html/queryhql.html#queryhql-select

I am trying to map the query result into a hash map like this

@Query(value = "SELECT NEW Map( PRODUCT_CATEGORY , COUNT(PRODUCT_CATEGORY) AS COUNTER )  from Product WHERE USER_ID=(SELECT USER_ID FROM USERS WHERE USERNAME=(:username)) ",nativeQuery = true)
    HashMap<Integer,Integer> getCategoryCountsWithUsername(@Param("username")String username);

But it throws an JdbcSyntaxErrorException. I am trying to solve this for like 1 hours already. Can someone help?

Upvotes: 0

Views: 151

Answers (2)

Marc Bannout
Marc Bannout

Reputation: 451

With a native query, your named parameter won't work. You need to remove the nativeQuery = true

Upvotes: 0

C&#233;sar Alves
C&#233;sar Alves

Reputation: 476

You are using a native query, not an HQL query. Check your SQL syntax.

Upvotes: 1

Related Questions