File tree 2 files changed +10
-1
lines changed
HibernateSpringBootBatchDeleteCascadeDelete/src/main/java/com/bookstore
2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change 1
1
package com .bookstore .repository ;
2
2
3
3
import com .bookstore .entity .Author ;
4
+ import java .util .List ;
5
+ import javax .persistence .QueryHint ;
6
+ import static org .hibernate .jpa .QueryHints .HINT_PASS_DISTINCT_THROUGH ;
4
7
import org .springframework .data .jpa .repository .JpaRepository ;
8
+ import org .springframework .data .jpa .repository .Query ;
9
+ import org .springframework .data .jpa .repository .QueryHints ;
5
10
import org .springframework .stereotype .Repository ;
6
11
7
12
@ Repository
8
13
public interface AuthorRepository extends JpaRepository <Author , Long > {
14
+
15
+ @ QueryHints (value = @ QueryHint (name = HINT_PASS_DISTINCT_THROUGH , value = "false" ))
16
+ @ Query (value = "SELECT DISTINCT a FROM Author a JOIN FETCH a.books b WHERE a.age < ?1" )
17
+ List <Author > fetchAuthorsAndBooks (int age );
9
18
}
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ public void batchAuthorsAndBooks() {
26
26
Author author = new Author ();
27
27
author .setName ("Name_" + i );
28
28
author .setGenre ("Genre_" + i );
29
- author .setAge (18 + i );
29
+ author .setAge (( int ) (( Math . random () + 0.1 ) * 100 ) );
30
30
31
31
for (int j = 0 ; j < 5 ; j ++) {
32
32
Book book = new Book ();
You can’t perform that action at this time.
0 commit comments