aesthetic improvements to pdf docs
This commit is contained in:
parent
43264d225a
commit
a7a6a21fb8
|
@ -652,14 +652,14 @@ Using the JPA-standard APIs, this would be a `CriteriaBuilder`, and we get it fr
|
|||
|
||||
[source,java]
|
||||
----
|
||||
CriteriaBuilder cb = entityManagerFactory.getCriteriaBuilder();
|
||||
CriteriaBuilder builder = entityManagerFactory.getCriteriaBuilder();
|
||||
----
|
||||
|
||||
But if we have a `SessionFactory`, we get something much better, a `HibernateCriteriaBuilder`:
|
||||
|
||||
[source,java]
|
||||
----
|
||||
HibernateCriteriaBuilder cb = sessionFactory.getCriteriaBuilder();
|
||||
HibernateCriteriaBuilder builder = sessionFactory.getCriteriaBuilder();
|
||||
----
|
||||
|
||||
The `HibernateCriteriaBuilder` extends `CriteriaBuilder` and adds many operations that JPQL doesn't have.
|
||||
|
@ -672,7 +672,7 @@ Either:
|
|||
|
||||
[source,java]
|
||||
----
|
||||
HibernateCriteriaBuilder cb =
|
||||
HibernateCriteriaBuilder builder =
|
||||
entityManagerFactory.unwrap(SessionFactory.class).getCriteriaBuilder();
|
||||
----
|
||||
|
||||
|
@ -680,7 +680,7 @@ Or simply:
|
|||
|
||||
[source,java]
|
||||
----
|
||||
HibernateCriteriaBuilder cb =
|
||||
HibernateCriteriaBuilder builder =
|
||||
(HibernateCriteriaBuilder) entityManagerFactory.getCriteriaBuilder();
|
||||
----
|
||||
====
|
||||
|
@ -689,18 +689,18 @@ We're ready to create a criteria query.
|
|||
|
||||
[source,java]
|
||||
----
|
||||
CriteriaQuery<Book> query = cb.createQuery(Book.class);
|
||||
CriteriaQuery<Book> query = builder.createQuery(Book.class);
|
||||
Root<Book> book = query.from(Book.class);
|
||||
Predicate where = cb.conjunction();
|
||||
Predicate where = builder.conjunction();
|
||||
if (titlePattern != null) {
|
||||
where = cb.and(where, cb.like(book.get(Book_.title), titlePattern));
|
||||
where = builder.and(where, builder.like(book.get(Book_.title), titlePattern));
|
||||
}
|
||||
if (namePattern != null) {
|
||||
Join<Book,Author> author = book.join(Book_.author);
|
||||
where = cb.and(where, cb.like(author.get(Author_.name), namePattern));
|
||||
where = builder.and(where, builder.like(author.get(Author_.name), namePattern));
|
||||
}
|
||||
query.select(book).where(where)
|
||||
.orderBy(cb.asc(book.get(Book_.title)));
|
||||
.orderBy(builder.asc(book.get(Book_.title)));
|
||||
----
|
||||
|
||||
Here, as before, the classes `Book_` and `Author_` are generated by Hibernate's <<metamodel-generator,JPA Metamodel Generator>>.
|
||||
|
@ -739,9 +739,9 @@ Update, insert, and delete queries work similarly:
|
|||
|
||||
[source,java]
|
||||
----
|
||||
CriteriaDelete<Book> delete = cb.createCriteriaDelete(Book.class);
|
||||
CriteriaDelete<Book> delete = builder.createCriteriaDelete(Book.class);
|
||||
Root<Book> book = delete.from(Book.class);
|
||||
delete.where(cb.lt(cb.year(book.get(Book_.publicationDate)), 2000));
|
||||
delete.where(builder.lt(builder.year(book.get(Book_.publicationDate)), 2000));
|
||||
session.createMutationQuery(delete).executeUpdate();
|
||||
----
|
||||
|
||||
|
@ -750,11 +750,11 @@ session.createMutationQuery(delete).executeUpdate();
|
|||
It's even possible to transform a HQL query string to a criteria query, and modify the query programmatically before execution:
|
||||
[source,java]
|
||||
----
|
||||
HibernateCriteriaBuilder cb = sessionFactory.getCriteriaBuilder();
|
||||
var query = cb.createQuery("from Book where year(publicationDate) > 2000", Book.class);
|
||||
HibernateCriteriaBuilder builder = sessionFactory.getCriteriaBuilder();
|
||||
var query = builder.createQuery("from Book where year(publicationDate) > 2000", Book.class);
|
||||
var root = (Root<Book>) query.getRootList().get(0);
|
||||
query.where(cb.like(root.get(Book_.title), cb.literal("Hibernate%")));
|
||||
query.orderBy(cb.asc(root.get(Book_.title)), cb.desc(root.get(Book_.isbn)));
|
||||
query.where(builder.like(root.get(Book_.title), builder.literal("Hibernate%")));
|
||||
query.orderBy(builder.asc(root.get(Book_.title)), builder.desc(root.get(Book_.isbn)));
|
||||
List<Book> matchingBooks = session.createSelectionQuery(query).getResultList();
|
||||
----
|
||||
====
|
||||
|
@ -958,13 +958,13 @@ Consider the following code:
|
|||
|
||||
[source,java]
|
||||
----
|
||||
var cb = sessionFactory.getCriteriaBuilder();
|
||||
var query = cb.createTupleQuery();
|
||||
var builder = sessionFactory.getCriteriaBuilder();
|
||||
var query = builder.createTupleQuery();
|
||||
var book = query.from(Book.class);
|
||||
var bookTitle = book.get(Book_.title);
|
||||
var bookIsbn = book.get(Book_.isbn);
|
||||
var bookPrice = book.get(Book_.price);
|
||||
query.select(cb.tuple(bookTitle, bookIsbn, bookPrice));
|
||||
query.select(builder.tuple(bookTitle, bookIsbn, bookPrice));
|
||||
var resultList = session.createSelectionQuery(query).getResultList();
|
||||
for (var result: resultList) {
|
||||
String title = result.get(bookTitle);
|
||||
|
|
|
@ -609,11 +609,11 @@ JPA provides a `@Lob` annotation which specifies that a field should be persiste
|
|||
****
|
||||
What the spec actually says is that the field should be persisted
|
||||
|
||||
> as a large object to a database-supported large object type.
|
||||
> ...as a large object to a database-supported large object type.
|
||||
|
||||
It's quite unclear what this means, and the spec goes on to say that
|
||||
|
||||
> the treatment of the `Lob` annotation is provider-dependent
|
||||
> ...the treatment of the `Lob` annotation is provider-dependent...
|
||||
|
||||
which doesn't help much.
|
||||
****
|
||||
|
@ -627,6 +627,7 @@ So unless you specifically need to use these JDBC LOB APIs, you _don't_ need the
|
|||
|
||||
Instead, as we just saw in <<column-lengths>>, all you need is to specify a large enough column `length` to accommodate the data you plan to write to that column.
|
||||
|
||||
[%unbreakable]
|
||||
[WARNING]
|
||||
// .PostgreSQL `BYTEA` and `TEXT`
|
||||
====
|
||||
|
|
|
@ -62,10 +62,20 @@ sidebar:
|
|||
title:
|
||||
align: center
|
||||
admonition:
|
||||
label:
|
||||
vertical-align: top
|
||||
padding: [4, 8, 4, 8]
|
||||
column-rule:
|
||||
style: solid
|
||||
width: 3
|
||||
color: #f0f0f0
|
||||
icon:
|
||||
tip:
|
||||
stroke-color: #FFC300
|
||||
warning:
|
||||
stroke-color: #FF5733
|
||||
caution:
|
||||
stroke-color: #FF5733
|
||||
heading:
|
||||
font:
|
||||
color: #b22222
|
||||
|
|
Loading…
Reference in New Issue