Spring JPA query results are multiple, but the return value is one, and the program does not report an error.

public interface UserRepository extends MongoRepository<User, Long> {
    User findByUsername(String username);
}

the above code uses the function of Spring JPA to find users according to their names, but multiple data can be queried in the database according to their names zong , and the return value of the findByUsername method is User, not List < User >. At this time, the expected result should be an error, but the program does not report an error, but returns the first item of multiple data.

excuse me, what is the reason for this? why did you report it correctly?

Sep.16,2021

User, so only return one
. If you change the declaration to List < User >, you can return multiple
. This is the advantage of JPA. How can you expect him to report a mistake

?
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b36ae2-343fd.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b36ae2-343fd.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?