无法在使用Spring Data JPA时提取结果集。

huangapple go评论64阅读模式
英文:

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:

{
&quot;timestamp&quot;: &quot;2020-09-25T06:28:05.202+0000&quot;,
&quot;status&quot;: 500,
&quot;error&quot;: &quot;Internal Server Error&quot;,
&quot;message&quot;: &quot;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)]&quot;,
&quot;path&quot;: &quot;/spacestudy/rockefeller/security/retrieveUserByNotRoleAssigned&quot;
}

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(&quot;select new map(u.nuserId,u.susername) from Users u where u.nuserId NOT IN :userRoleMappingList&quot;)
List&lt;Users&gt; findByUsersNotassignedRole(@Param(value = &quot;userRoleMappingList&quot;) List&lt;Integer&gt; userRoleMappingList);

And my service, I wrote like the following,

public List&lt;Users&gt; retrieveUsersByNotassignedRoles() {
	// TODO Auto-generated method stub
	
	List&lt;Integer&gt; userRoleMappingList = userRoleMappingRepoObj.findByUserId();
	
	return userRepoObj.findByUsersNotassignedRole(userRoleMappingList);
 }

and UserRoleMappingRepository.java coded with,

@Query(&quot;select new map(ur.nuserId) from UserRoleMapping ur&quot;)
List&lt;Integer&gt; findByUserId();

Where did I go in the wrong direction?

答案1

得分: 1

userRoleMappingList应该是一个用户ID列表。

英文:

userRoleMappingList should be a list of userIds.

huangapple
  • 本文由 发表于 2020年9月25日 21:07:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/64064803.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定