简体   繁体   中英

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.

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:

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

But the method returns a list of three identical entries:

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

I have tried using findByUserId(String userId), but it has the same result.

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. The column that had the @Id didn't have unique data as opposed to the other column.

Changing the annotation's place solved the issue.

Thank you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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