File tree Expand file tree Collapse file tree 3 files changed +11
-15
lines changed
HibernateSpringBootJoinFormula/src/main/java/com/bookstore Expand file tree Collapse file tree 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 {
3232 + "WHERE b.price < price AND b.author_id = author_id "
3333 + "ORDER BY b.price DESC "
3434 + "LIMIT 1)" )
35- private Book prevBook ;
35+ private Book nextBook ;
3636
3737 public Long getId () {
3838 return id ;
@@ -74,13 +74,13 @@ public void setPrice(int price) {
7474 this .price = price ;
7575 }
7676
77- public Book getPrevBook () {
78- return prevBook ;
77+ public Book getNextBook () {
78+ return nextBook ;
7979 }
8080
81- public void setPrevBook (Book prevBook ) {
82- this .prevBook = prevBook ;
83- }
81+ public void setNextBook (Book nextBook ) {
82+ this .nextBook = nextBook ;
83+ }
8484
8585 @ Override
8686 public String toString () {
Original file line number Diff line number Diff line change 33import com .bookstore .entity .Book ;
44import org .springframework .data .jpa .repository .JpaRepository ;
55import org .springframework .stereotype .Repository ;
6- import org .springframework .transaction .annotation .Transactional ;
76
87@ 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 > {
139}
Original file line number Diff line number Diff line change @@ -18,10 +18,10 @@ public BookstoreService(BookRepository bookRepository) {
1818 @ Transactional (readOnly = true )
1919 public void fetchBooks () {
2020
21- Book book = bookRepository .findById (4L ).orElseThrow ();
22- Book prevBook = book .getPrevBook ();
21+ Book book = bookRepository .findById (7L ).orElseThrow ();
22+ Book nextBook = book .getNextBook ();
2323
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 );
2626 }
2727}
You can’t perform that action at this time.
0 commit comments