Hibernate Class Cast Exception

前端 未结 1 816
旧时难觅i
旧时难觅i 2021-01-25 03:45

I am getting a class cast exception with hibernate when trying to cast the result set to the mapping class... I am able to see the data in the result set that is returned...howe

1条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-25 04:09

    For tests I recommend you to put a try-catch clause around the statement which is producing the class cast exception, set a breakpoint in the catch block and look which class the i-th element really is.

    To your problem:

    You are using the HQL SELECT statement. The query with this statement returns a list, but the elements of the list are not necessarily instances of EQP_TU; they also can be an array of object.

    Solution for you:

    Use the FROM statement instead of the SELECT statement. In your code:

    String queryString = "FROM EQP_UT AS A " +
                    "LEFT JOIN A.eqp_comp AS B " +
                    "WHERE A.INITIAL||A.NUMBER IN (:carList) AND A.INITIAL IN (:initList) AND A.NUMBER IN (:numberList) " + 
                    "AND B.TRUK_AXL_CNT > 0";
    

    Then you can be sure to get a list with instances of the class you mentioned after FROM (EQP_UT in your code).

    0 讨论(0)
提交回复
热议问题