public List<Client> findClientByAssociateUser(String userId) {
logger.info("Enter find list of clients by this user");
org.hibernate.Query query = sessionFactory.getCurrentSession()
.createQuery("SELECT c.id, c.clientName, c.billingAddress,c.contactNumber"
+ " from Client c, User ud"
+ " WHERE ud.id = c.userId and ud.id = :id")
.setString("id", userId);
List<Client> result = (List<Client>) query.list();
logger.info("Exit find list of clients");
return result;
}
public ModelAndView userDetails(@PathVariable String id, HttpServletRequest request) {
ModelAndView mvc = new ModelAndView();
List<Client> clientList = userRepository.findClientByAssociateUser(id.toString());
mvc.addObject("clientList", clientList);
for (Client client : clientList) {
System.out.println("Client Name{" + client.getClientName());
}
mvc.setViewName(MANAGEUSER_PREFIX + "details");
return mvc;
}
我得到了:
Ljava.lang.Object; cannot be cast to Client
答案 0 :(得分:0)
查询中的返回类型为List<Object[] >.
因为您的查询是
SELECT c.id, c.clientName, c.billingAddress,c.c......
更改
List<Client> result = (List<Client>) query.list();
然后根据
进行处理到
List<Object[]> result = (List<Object[]>) query.list();
或将查询更改为
SELECT c from Client c......