File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Spring_part_12/src/main/java/spring/oldboy/database/repository/user_repository Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ package spring .oldboy .database .repository .user_repository ;
2+
3+ /* Part 10: Lesson 55 - применение аннотаций @Lock и @QueryHints в запросах к БД */
4+
5+ import jakarta .persistence .LockModeType ;
6+ import jakarta .persistence .QueryHint ;
7+ import org .springframework .data .domain .Sort ;
8+ import org .springframework .data .jpa .repository .JpaRepository ;
9+ import org .springframework .data .jpa .repository .Lock ;
10+ import org .springframework .data .jpa .repository .QueryHints ;
11+ import org .springframework .stereotype .Repository ;
12+ import spring .oldboy .database .entity .User ;
13+
14+ import java .time .LocalDate ;
15+ import java .util .List ;
16+
17+ /* Изменим наш класс на интерфейс и расширим JpaRepository */
18+ @ Repository
19+ public interface SixthUserRepository extends JpaRepository <User , Long > {
20+
21+ /* Part 10: Lesson 55: Применим @Lock */
22+ @ Lock (LockModeType .PESSIMISTIC_READ )
23+ List <User > findTop3ByBirthDateBefore (LocalDate birthDate , Sort sort );
24+
25+ /* Part 10: Lesson 55: Применим @Lock */
26+ @ QueryHints (@ QueryHint (name = "org.hibernate.fetchSize" , value = "1" ))
27+ @ Lock (LockModeType .PESSIMISTIC_WRITE )
28+ List <User > findTop2ByBirthDateBefore (LocalDate birthDate , Sort sort );
29+
30+ }
You can’t perform that action at this time.
0 commit comments