I am stuck with the issue of getting the queries worked. I am using Many-To-Many Unidirectional relationship between User and Role i.e. i want to list the Roles of a User.
I am getting "Invalid Colum" error for Native SQL query
Here is my Native SQL query
[color=blue]String sql = "select c.last_name as {c.lastName}, c.first_name as
{c.firstName} from ced c where c.bemsid=:id";
SQLQuery query = session.createSQLQuery(sql).addEntity("c",User.class);[/color]
I am getting following error for HQL query
org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: bemsId of: com.mycompany.User [select user.lastName, user.firstName from com.mycompany.User as user where user.bemsId=:id]; nested exception is org.hibernate.QueryException: could not resolve property: bemsId of: com.mycompany.User
Here is my HQL query
[color=blue]String sql = "select user.lastName, user.firstName from User as user " +
"where user.bemsId=:id";
Query query = session.createQuery(sql);
query.setParameter("id", bemsId); [/color]
Any pointers /suggestions on writing Native SQL / HQL queries for Many-To-Many relationship will be highly appreciated.
Also please let me know how do i Iterate thru the Objects returned by the query. The following results in ClassCastException
userList=testSpringBean.getUser(bemsId);
System.out.println("User List:"+userList.size()); // returns size = 2
user= (User) userList.get(0);
role = (Role) userList.get(1);
String lastName = user.getLastName();
String roleName = role.getName();
P.S. I am using Hibernate 3.1 and have read the documentation atleast 3-5 times and found quite deprecated methods there. Also the examples mentioned in the V3 documentation for Native SQL queries using Many-To-Many relationship is deprecated or doesn't work (
http://www.hibernate.org/hib_docs/v3/re ... /#querysql) .
Regards
Bansi