0
  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
4

1 に答える 1

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......
于 2013-03-20T17:04:44.757 に答える