This is rows in database.
group userid
1 a
2 b
1 c
3 d
I want to query using @query annotation about
@Query(value ="SELECT *, count(*) as cnt FROM user group by body order by cnt DESC", nativeQuery = true)
List<User> getGroupRanking();
and, i expect to result about
group cnt
1 2
2 1
3 d
but List<User>
collection is not accept to 'cnt' attribute which was alias.
another reason not to accept, User defined class was not containing 'cnt' attribute. i was defined 'cnt' attribute in User Class like following code.
public class User{
@Column(name ="group")
private String group;
..
private Integer cnt;
public Integer getCnt(){ return cnt; }
public void setCnt(Integer cnt){ this.cnt = cnt; }
}
Although I will prevent to update the schema, The above code update the schema. because
appConfig.xml configuration was set like this
<prop key="hibernate.hbm2ddl.auto">update</prop>
i don't want to update schema, and i want to display cnt attribute in JSP file through User Class(bean) when i using @Query annotation. how to accept a 'cnt' attribute using the User class without update schema? 'as' keyword usage not containing in detail(link)