简体   繁体   English

Spring Framework和Jpa Repository返回无效的数据库数据

[英]Spring Framework and Jpa Repository returns invalid DB data

I'm testing a service that returns some information from the DB. 我正在测试一种从数据库返回一些信息的服务。

I'm using Spring framework and JPA Repository to obtain the data from the DB in order to compare it with the service output. 我正在使用Spring框架和JPA存储库从数据库获取数据,以便将其与服务输出进行比较。

public interface UsersAccountsRepo extends JpaRepository<UsersAccounts, Long> {

    List<UsersAccounts> findAllByUserId(String userId);

}

Calling the method: 调用方法:

List<UsersAccounts> usersAccounts = UsersAccountsRepo.findAllByUserId(userId);

The db has 3 entries for this userId = 123, with the following format: 该数据库具有3个用于此userId = 123的条目,格式如下:

  • 123 / 30001 123/30001
  • 123 / 30002 123/30002
  • 123 / 30003 123/30003

But the method returns a list of three identical entries: 但是该方法返回三个相同条目的列表:

  • 123 / 30001 123/30001
  • 123 / 30001 123/30001
  • 123 / 30001 123/30001

I have tried using findByUserId(String userId), but it has the same result. 我尝试使用findByUserId(String userId),但结果相同。

Thank you. 谢谢。

Sorry for not giving out all the relevant information, I didn't think it had an impact. 很抱歉没有提供所有相关信息,我认为这没有影响。

As it turns out, the table mapping had the @Id annotation set on the wrong column. 事实证明,表映射在错误的列上设置了@Id注释。 The column that had the @Id didn't have unique data as opposed to the other column. 与其他列相反,具有@Id的列没有唯一数据。

Changing the annotation's place solved the issue. 更改注释的位置可以解决此问题。

Thank you. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM