For example, suppose the entity Book is defined as follows:
@Entity
class Book {
@Id String isbn;
String title;
...
}
Then we might define:
@Find Book getBookForIsbn(String isbn); @Find List<Book> getBooksWithTitle(String title);
Notice that:
@Find
methods—they may be named arbitrarily, and their names
encode no semantics.
The Metamodel Generator automatically creates an "implementation"
of every finder method in the static metamodel class Books_.
The generated method may be called according to the following
protocol:
Book book = Books_.findBookByIsbn(session, isbn); List<Book> books = Books_.getBooksWithTitle(session, String title);
Notice the extra parameter of type EntityManager at the
start of the parameter list.
Alternatively, the type to which the annotated method belongs may
also declare an abstract method with no parameters which returns
one of the types jakarta.,
org.,
or org., for example:
EntityManager entityManager();In this case:
static,
EntityManager, and
@SQL.
Thus, the generated method may be called according to the following protocol:
Books books = new Books_(session); Book book = books.getBookForIsbn(isbn); List<Book> books = books.getBooksWithTitle(String title);
This is reminiscent of traditional DAO-style repositories.
The return type of an annotated method must be an entity type E,
or one of the following types:
java.util.List<E> ,
org.hibernate.query.Query<E> ,
org.hibernate.query.SelectionQuery<E> ,
jakarta.persistence.Query<E> , or
jakarta.persistence.TypedQuery<E> .
The names and types of the parameters of a finder method must match exactly with the names and types of persistent fields of the entity type returned by the finder method.
@Id or
@EmbeddedId field of the entity, the finder method uses
jakarta.persistence.EntityManager#find(Class, Object)
to retrieve the entity.
@NaturalId
field of the entity, the finder method uses
org.hibernate.Session#byNaturalId(Class) to retrieve the
entity.
As an exception, the method may have at most one parameter of
type EntityManager, Session,
StatelessSession, or Mutiny.Session.
HQL, SQL
| Modifier and Type | Method and Description |
|---|---|
| public String[] |
| enabledFetchProfiles | back to summary |
|---|---|
| public String[] enabledFetchProfiles() | |