Last active
May 15, 2017 03:31
-
-
Save thjanssen/edff8b22b5b4b3220fb292c868efefa9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity | |
public class Book implements Comparable<Book> { | |
@Id | |
@GeneratedValue(strategy = GenerationType.AUTO) | |
@Column(name = "id", updatable = false, nullable = false) | |
private Long id; | |
@Version | |
private int version; | |
private String title; | |
@ManyToMany | |
@JoinTable(name = "book_author", | |
joinColumns = { @JoinColumn(name = "fk_book") }, | |
inverseJoinColumns = { @JoinColumn(name = "fk_author") }) | |
// requires sorting or ordering | |
private SortedSet<Author> authors = new TreeSet<Author>(); | |
... | |
@Override | |
public int compareTo(Book o) { | |
log.info("compare"); | |
return title.compareTo(o.getTitle()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
08:58:26,871 DEBUG SQL:92 - select author0_.id as id1_0_0_, book2_.id as id1_1_1_, author0_.name as name2_0_0_, author0_.version as version3_0_0_, book2_.title as title2_1_1_, book2_.version as version3_1_1_, books1_.fk_author as fk_autho2_2_0__, books1_.fk_book as fk_book1_2_0__ from Author author0_ inner join book_author books1_ on author0_.id=books1_.fk_author inner join Book book2_ on books1_.fk_book=book2_.id where author0_.id=? order by book2_.title asc | |
08:58:27,022 INFO TestSortVsOrder:46 - Author [id=1, name=B Author] | |
08:58:27,024 INFO TestSortVsOrder:48 - Book [id=3, title=A Book] | |
08:58:27,024 INFO TestSortVsOrder:48 - Book [id=1, title=B Book] | |
08:58:27,024 INFO TestSortVsOrder:48 - Book [id=2, title=C Book] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18:21:30,966 DEBUG SQL:92 - select author0_.id as id1_0_0_, book2_.id as id1_1_1_, author0_.name as name2_0_0_, author0_.version as version3_0_0_, book2_.title as title2_1_1_, book2_.version as version3_1_1_, books1_.fk_author as fk_autho2_2_0__, books1_.fk_book as fk_book1_2_0__ from Author author0_ inner join book_author books1_ on author0_.id=books1_.fk_author inner join Book book2_ on books1_.fk_book=book2_.id where author0_.id=? | |
18:21:31,097 INFO SortById:13 - SortById.compare | |
18:21:31,098 INFO SortById:13 - SortById.compare | |
18:21:31,098 INFO SortById:13 - SortById.compare | |
18:21:31,098 INFO SortById:13 - SortById.compare | |
18:21:31,105 INFO TestSortVsOrder:43 - Author [id=1, name=B Author] | |
18:21:31,118 INFO TestSortVsOrder:45 - Book [id=1, title=B Book] | |
18:21:31,118 INFO TestSortVsOrder:45 - Book [id=2, title=C Book] | |
18:21:31,119 INFO TestSortVsOrder:45 - Book [id=3, title=A Book] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18:10:22,018 DEBUG SQL:92 - select author0_.id as id1_0_0_, book2_.id as id1_1_1_, author0_.name as name2_0_0_, author0_.version as version3_0_0_, book2_.title as title2_1_1_, book2_.version as version3_1_1_, books1_.fk_author as fk_autho2_2_0__, books1_.fk_book as fk_book1_2_0__ from Author author0_ inner join book_author books1_ on author0_.id=books1_.fk_author inner join Book book2_ on books1_.fk_book=book2_.id where author0_.id=? | |
18:10:22,085 INFO Book:107 - compare | |
18:10:22,085 INFO Book:107 - compare | |
18:10:22,085 INFO Book:107 - compare | |
18:10:22,087 INFO TestSortVsOrder:43 - Author [id=1, name=B Author] | |
18:10:22,088 INFO TestSortVsOrder:45 - Book [id=3, title=A Book] | |
18:10:22,089 INFO TestSortVsOrder:45 - Book [id=1, title=B Book] | |
18:10:22,089 INFO TestSortVsOrder:45 - Book [id=2, title=C Book] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SortById implements Comparator<Book> { | |
Logger log = Logger.getLogger(SortById.class.getSimpleName()); | |
@Override | |
public int compare(Book o1, Book o2) { | |
log.info("SortById.compare"); | |
return o1.getId().compareTo(o2.getId()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment