HHH-17039 fix Session vs EntityManager confusion in doc code examples
This commit is contained in:
parent
36fc27dd4a
commit
ffbced83a9
|
@ -467,7 +467,7 @@ public class BookResource {
|
||||||
@GET @Path("books/{titlePattern}/{page:\\d+}")
|
@GET @Path("books/{titlePattern}/{page:\\d+}")
|
||||||
public List<Book> findBooks(String titlePattern, int page) {
|
public List<Book> findBooks(String titlePattern, int page) {
|
||||||
var books = sessionFactory.fromTransaction(session -> {
|
var books = sessionFactory.fromTransaction(session -> {
|
||||||
return entityManager.createQuery("from Book where title like ?1 order by title", Book.class)
|
return session.createSelectionQuery("from Book where title like ?1 order by title", Book.class)
|
||||||
.setParameter(1, titlePattern)
|
.setParameter(1, titlePattern)
|
||||||
.setPage(Page.page(RESULTS_PER_PAGE, page))
|
.setPage(Page.page(RESULTS_PER_PAGE, page))
|
||||||
.getResultList();
|
.getResultList();
|
||||||
|
@ -485,9 +485,9 @@ Let's hit the code with our favorite thing, the Extract Method refactoring. We o
|
||||||
|
|
||||||
[source,java]
|
[source,java]
|
||||||
----
|
----
|
||||||
static List<Book> findBooksByTitleWithPagination(EntityManager entityManager,
|
static List<Book> findBooksByTitleWithPagination(Session session,
|
||||||
String titlePattern, Page page) {
|
String titlePattern, Page page) {
|
||||||
return entityManager.createQuery("from Book where title like ?1 order by title", Book.class)
|
return session.createSelectionQuery("from Book where title like ?1 order by title", Book.class)
|
||||||
.setParameter(1, titlePattern)
|
.setParameter(1, titlePattern)
|
||||||
.setPage(page)
|
.setPage(page)
|
||||||
.getResultList();
|
.getResultList();
|
||||||
|
@ -509,9 +509,9 @@ We need a place to put the annotation, so lets move our query method to a new cl
|
||||||
query="from Book where title like :title order by title")
|
query="from Book where title like :title order by title")
|
||||||
class Queries {
|
class Queries {
|
||||||
|
|
||||||
static List<Book> findBooksByTitleWithPagination(EntityManager entityManager,
|
static List<Book> findBooksByTitleWithPagination(Session session,
|
||||||
String titlePattern, Page page) {
|
String titlePattern, Page page) {
|
||||||
return entityManager.createNamedQuery("findBooksByTitle", Book.class)
|
return session.createNamedQuery("findBooksByTitle", Book.class)
|
||||||
.setParameter("title", titlePattern)
|
.setParameter("title", titlePattern)
|
||||||
.setPage(page)
|
.setPage(page)
|
||||||
.getResultList();
|
.getResultList();
|
||||||
|
|
Loading…
Reference in New Issue