Last active
March 15, 2017 08:46
-
-
Save thjanssen/22ce2b57a14a10057b63ef601aaf95c6 to your computer and use it in GitHub Desktop.
This file contains 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 { | |
@Id | |
@GeneratedValue(strategy = GenerationType.AUTO) | |
@Column(name = “id”, updatable = false, nullable = false) | |
private Long id; | |
private LocalDate publishingDate; | |
… | |
} |
This file contains 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
Query q = em.createQuery(“SELECT b.title, count(r.id) FROM Book b INNER JOIN Review r ON r.fkBook = b.id GROUP BY b.title”); | |
Object[] r = (Object[]) q.getSingleResult(); |
This file contains 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
05:44:59,939 DEBUG [org.hibernate.SQL] - | |
select | |
book0_.title as col_0_0_, | |
count(review1_.id) as col_1_0_ | |
from | |
Book book0_ | |
inner join | |
Review review1_ | |
on ( | |
review1_.fkBook=book0_.id | |
) | |
group by | |
book0_.title |
This file contains 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
MultiIdentifierLoadAccess<Book> multi = session.byMultipleIds(Book.class); | |
List<Book> books = multi.multiLoad(1L, 2L, 3L); |
This file contains 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
05:44:33,872 DEBUG [org.hibernate.SQL] - | |
select | |
book0_.id as id1_0_0_, | |
book0_.publishingDate as publishi2_0_0_, | |
book0_.title as title3_0_0_, | |
book0_.version as version4_0_0_ | |
from | |
Book book0_ | |
where | |
book0_.id in ( | |
?,?,? | |
) |
This file contains 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
16:15:33,545 DEBUG [org.hibernate.SQL] – insert into Book (price, publishingDate, title, version, id) values (?, ?, ?, ?, ?) | |
16:15:33,550 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] – binding parameter [1] as [DOUBLE] – [null] | |
16:15:33,551 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] – binding parameter [2] as [DATE] – [2017-04-04] | |
16:15:33,552 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] – binding parameter [3] as [VARCHAR] – [Hibernate Tips] | |
16:15:33,553 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] – binding parameter [4] as [INTEGER] – [0] | |
16:15:33,554 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] – binding parameter [5] as [BIGINT] – [1] |
This file contains 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
Stream<Object[]> books = session.createNativeQuery("SELECT b.title, b.publishingDate FROM book b").stream(); | |
books.map(b -> new BookValue((String)b[0], (Date)b[1])) | |
.map(b -> b.getTitle() + " was published on " + b.getPublishingDate()) | |
.forEach(m -> log.info(m)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment