Gavin King (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiYWEzYjA0YTg1...
) / New Feature (
https://hibernate.atlassian.net/browse/HHH-16899?atlOrigin=eyJpIjoiYWEzYj...
) HHH-16899 (
https://hibernate.atlassian.net/browse/HHH-16899?atlOrigin=eyJpIjoiYWEzYj...
) CriteriaDefinition (
https://hibernate.atlassian.net/browse/HHH-16899?atlOrigin=eyJpIjoiYWEzYj...
)
Issue Type: New Feature Assignee: Unassigned Created: 05/Jul/2023 09:16 AM Priority: Major
Reporter: Gavin King (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
I propose a utility class CriteriaDefinition that makes it easier to write criteria
queries.
Instead of:
var builder = sessionFactory.getCriteriaBuilder();
var query = builder.createQuery(Book.class);
var book = query.from(Book.class);
query.where(builder.like(book.get(Book_.title), "%Hibernate%" ));
query.orderBy(builder.desc(book.get(Book_.publicationDate)),
builder.asc(book.get(Book_.isbn)));
book.fetch(Book_.authors);
List<Book> books =
session.createSelectionQuery(query)
.setMaxResults(10)
.getResultList();
You can write:
List<Book> books
= new CriteriaDefinition<>(session, Book.class) {
public void define() {
var book = from(Book.class);
where(like(book.get(Book_.title), "%Hibernate%" ));
orderBy(desc(book.get(Book_.publicationDate)),
asc(book.get(Book_.isbn)));
book.fetch(Book_.authors);
}
}
.createSelectionQuery()
.setMaxResults(10)
.getResultList();
WDYT?
(
https://hibernate.atlassian.net/browse/HHH-16899#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16899#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100229- sha1:634ba05 )