我正在UserRequest使用 JPA Query 从 DB 中检索对象,如下所示。
@Query("SELECT req.supervisorEmail from User u, UserRequest as req WHERE u.username = req.userRequestName and req.userRequestRole= '4' and u.active=true")
public List<UserRequest> getSupervisorEmailIds();
我有UserRequest如下 POJO 类。
public class UserRequest implements Identifiable<Long>, LazilyLoadable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@JsonIgnore
private Long id;
@Column(name = "supervisor_email")
private String supervisorEmail;
@Column(name="user_request_name")
private String userRequestName;
@Column(name="user_request_role")
private String userRequestRole;
}
当我试图迭代UserRequest对象时,我得到ClassCastException了下面的代码。
List<UserRequest> supervisorEmailIds = userService.getSupervisorEmailIds();
for(UserRequest s: supervisorEmailIds) { // throwing exception on this line.
if(s!=null) {
System.out.println("Printing -->"+s.getSupervisorEmail());
}
System.out.println("Null error");
}
以下是我得到的错误。
2019-02-22 00:34:26,719 [http-9191-1] ERROR com.cat.pscs.api.controller.BaseController: 83 - Unhandled exception while processing request for URL : http://localhost:9191/security/users/get-supervisor-emailids with exception : java.lang.String cannot be cast to com.cat.pscs.security.model.UserRequest
java.lang.ClassCastException:java.lang.String 无法在 com.cat.pscs.security.controller.UserController.getSupervisorEmailIds 中转换为 com.cat.pscs.security.model.UserRequest(UserController.java:320)
一只名叫tom的猫
人到中年有点甜
阿晨1998
相关分类