Querieseasy0-2 years
A repository declares `List<User> findByEmaill(String email)` — a typo. When does that fail: at compile time, at startup, on the first call, or never? And at what point should a derived query method stop being a method name?
At startup. The name is valid Java, so the compiler cannot help, but Spring Data parses every derived query name when it builds the repository proxy, and it checks each property in the name against the entity. Emaill is not a property of User, so it throws a PropertyReferenceException and the application fails to start, naming the method. That is the right time to find out. The limit is readability, not the parser: once a name needs more than about three conditions, or any join, subquery, aggregate or optional filter, it should become a @Query or a Specification, because the parser will happily accept a method name nobody can review.
PreviousCode adds a new `Book` to `author.getBooks()` and persists both. Every assertion in the method passes — `author.getBooks()` contains the book — but in the database `book.author_id` is `NULL`. No error was thrown. What went wrong?Next An endpoint lists 500 authors with their books and takes eleven seconds; the code has no loop over queries anywhere. A teammate fixes it with `select a from Author a join fetch a.books`, and it is fast — but two authors have vanished from the list. Explain both problems.