英文:
Could not extract ResultSet while using Spring Data JPA
问题
我正在尝试使用Spring Boot和Spring Data JPA从我的数据库中提取结果集。当我应用JPA查询时,在我的Postman应用程序中出现以下错误:
{
"timestamp": "2020-09-25T06:28:05.202+0000",
"status": 500,
"error": "Internal Server Error",
"message": "Parameter value element [{0=com.spacestudy.model.Users@2357844c}] did not match expected type [java.lang.Integer (n/a)]; nested exception is java.lang.IllegalArgumentException: Parameter value element [{0=com.spacestudy.model.Users@2357844c}] did not match expected type [java.lang.Integer (n/a)]",
"path": "/spacestudy/rockefeller/security/retrieveUserByNotRoleAssigned"
}
在我的STS编辑器控制台中,我得到了以下消息:
java.lang.IllegalArgumentException: 参数值元素 [{0=com.spacestudy.model.Users@2357844c}] 与预期类型 [java.lang.Integer (n/a)]
我的仓库 UserRepository.java 的代码如下:
@Query("select new map(u.nuserId,u.susername) from Users u where u.nuserId NOT IN :userRoleMappingList")
List<Users> findByUsersNotassignedRole(@Param(value = "userRoleMappingList") List<Integer> userRoleMappingList);
我的服务层,我写了以下内容:
public List<Users> retrieveUsersByNotassignedRoles() {
// TODO Auto-generated method stub
List<Integer> userRoleMappingList = userRoleMappingRepoObj.findByUserId();
return userRepoObj.findByUsersNotassignedRole(userRoleMappingList);
}
而 UserRoleMappingRepository.java 的代码如下:
@Query("select new map(ur.nuserId) from UserRoleMapping ur")
List<Integer> findByUserId();
我在哪里走错了?
英文:
I am trying to extract result set from my database using Spring Boot and Spring Data jpa. When I am applying jpa query I am getting the following error in my Postman application:
{
"timestamp": "2020-09-25T06:28:05.202+0000",
"status": 500,
"error": "Internal Server Error",
"message": "Parameter value element [{0=com.spacestudy.model.Users@2357844c}] did not match expected type [java.lang.Integer (n/a)]; nested exception is java.lang.IllegalArgumentException: Parameter value element [{0=com.spacestudy.model.Users@2357844c}] did not match expected type [java.lang.Integer (n/a)]",
"path": "/spacestudy/rockefeller/security/retrieveUserByNotRoleAssigned"
}
and in my STS editor console, I am getting the following message,
java.lang.IllegalArgumentException: Parameter value element [{0=com.spacestudy.model.Users@2357844c}] did not match expected type [java.lang.Integer (n/a)
My repository UserRepository.java is codded like the following,
@Query("select new map(u.nuserId,u.susername) from Users u where u.nuserId NOT IN :userRoleMappingList")
List<Users> findByUsersNotassignedRole(@Param(value = "userRoleMappingList") List<Integer> userRoleMappingList);
And my service, I wrote like the following,
public List<Users> retrieveUsersByNotassignedRoles() {
// TODO Auto-generated method stub
List<Integer> userRoleMappingList = userRoleMappingRepoObj.findByUserId();
return userRepoObj.findByUsersNotassignedRole(userRoleMappingList);
}
and UserRoleMappingRepository.java coded with,
@Query("select new map(ur.nuserId) from UserRoleMapping ur")
List<Integer> findByUserId();
Where did I go in the wrong direction?
答案1
得分: 1
userRoleMappingList应该是一个用户ID列表。
英文:
userRoleMappingList should be a list of userIds.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论