File tree 3 files changed +11
-15
lines changed
HibernateSpringBootJoinFormula/src/main/java/com/bookstore
3 files changed +11
-15
lines changed Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ public class Book implements Serializable {
32
32
+ "WHERE b.price < price AND b.author_id = author_id "
33
33
+ "ORDER BY b.price DESC "
34
34
+ "LIMIT 1)" )
35
- private Book prevBook ;
35
+ private Book nextBook ;
36
36
37
37
public Long getId () {
38
38
return id ;
@@ -74,13 +74,13 @@ public void setPrice(int price) {
74
74
this .price = price ;
75
75
}
76
76
77
- public Book getPrevBook () {
78
- return prevBook ;
77
+ public Book getNextBook () {
78
+ return nextBook ;
79
79
}
80
80
81
- public void setPrevBook (Book prevBook ) {
82
- this .prevBook = prevBook ;
83
- }
81
+ public void setNextBook (Book nextBook ) {
82
+ this .nextBook = nextBook ;
83
+ }
84
84
85
85
@ Override
86
86
public String toString () {
Original file line number Diff line number Diff line change 3
3
import com .bookstore .entity .Book ;
4
4
import org .springframework .data .jpa .repository .JpaRepository ;
5
5
import org .springframework .stereotype .Repository ;
6
- import org .springframework .transaction .annotation .Transactional ;
7
6
8
7
@ Repository
9
- public interface BookRepository extends JpaRepository <Book , Long > {
10
-
11
- @ Transactional (readOnly = true )
12
- Book findByTitle (String title );
8
+ public interface BookRepository extends JpaRepository <Book , Long > {
13
9
}
Original file line number Diff line number Diff line change @@ -18,10 +18,10 @@ public BookstoreService(BookRepository bookRepository) {
18
18
@ Transactional (readOnly = true )
19
19
public void fetchBooks () {
20
20
21
- Book book = bookRepository .findById (4L ).orElseThrow ();
22
- Book prevBook = book .getPrevBook ();
21
+ Book book = bookRepository .findById (7L ).orElseThrow ();
22
+ Book nextBook = book .getNextBook ();
23
23
24
- System .out .println ("Fetched book with id 4 : " + book );
25
- System .out .println ("Fetched book with next smallest price: " + prevBook );
24
+ System .out .println ("Fetched book with id 7 : " + book );
25
+ System .out .println ("Fetched book with next smallest price: " + nextBook );
26
26
}
27
27
}
You can’t perform that action at this time.
0 commit comments