I realized this during the research & hence changed the query which works now
String sql = "select {c.*}, {u.*} from ced c, user_roles u, user_group_roles ugr " +
"where ugr.user_id=c.id and ugr.role_id=u.id and ugr.user_id=20";But i know this is not the ideal or recommended way. Also i am getting
ClassCastException as it is unable to handle the results returned by the query as shown below
Code:
[i]List userList=testSpringBean.getUser(userId);
System.out.println("User List:"+userList.size());
for (Iterator it = userList.iterator(); it.hasNext();) {
user= (User) it.next();
/* The exception occurs at the above line as the query returned two objects i.e. User & Role . Not sure how to handle this situation. Any pointers/suggestions will be highly appreciated*/
}
eh? of course it returns two objects since you told it to ;)
So the return value will be an Object[] where 0 is user and 1 is role.
Quote:
Max the reason i am using Native SQL is two-fold reason
1) The team has good experience in writing SQL queries
Sure, but what I would call "normal" queries that does not involve db specific or any "special" magic is so much easier to express and read in HQL than native sql.
Quote:
2) Native SQL is highly recommended for writing Complex queries, subqueries, complex expressions such as
select (select count(id) from Foo) / (select count(id) from Bar) from Something
Yes, subslects in the "select" clause is not permitted in HQL....but otherwise HQL will most likely suffice.