Reputation: 2348
Is there any way to Cast hibernate Query result to Object instead of list array.
Query q1 = session.createQuery("from userTable where id ='1234'");
List userList = q1.list(); >> cast to object of UserBean class type ??
UserBean user = (UserBean)userList.get(0);
System.out.println(user.getName);
System.out.println(user.getAge);
.....
System.out.println(user.getPhone);
UserBean class is mapped with a table name userTable and i wish to get the column value of one id
which is primary key of the table.
Please see at line 2, List userList = q1.list()
?? can we cast/convert to object of type class anyhow.
Upvotes: 1
Views: 3282
Reputation: 13161
Why don't you use this?
UserBean user = (UserBean) q1.getSingleResult();
Upvotes: 2