spring - java.lang.String cannot be cast to rh.com.app.domain.A
黄舟
黄舟 2017-04-18 10:38:49
0
2
343
黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(2)
黄舟

The poster should write hibernate hql statement question:

SELECT r.Id FROM A r WHERE r.Status = :edcbatchStatus

This hql should be taken out after executionid的类型集合。根据报错信息,结果类型为List<String>,在这里,强转类型为List<A>An exception will be thrown. There are following solutions:

  • If you just want to get a collection of ids, then modify the type of forced conversion

List<String> agencies = (List<String>)query.getResultList();
  • If you want to get the entire object, you need to modify the hql statement

SELECT * FROM A r WHERE r.Status = :edcbatchStatus
伊谢尔伦

Although I am not familiar with Spring and haven’t written Java for a long time, I can see some problems from this code

From the error message, there is a problem when converting String to type A. There is only one sentence in the code for conversion:

List<A> agencies = (List<A>)query.getResultList();

That might be getResultList() 本身取得的是一个 List<String>。从 SQL 来看,select r.Id, then this guess is reasonable.

So either change the return value to List<String>,要么在 SQL 里取得整个对象(还会有一些映射啊什么的,只能假设你已经配置好了),比如 select r.* from ....

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!