big code example in package doc for org.hibernate.annotations.processing
This commit is contained in:
parent
3b31351234
commit
5fa08123b3
|
@ -8,14 +8,112 @@
|
|||
/**
|
||||
* Annotations used to drive annotation processors:
|
||||
* <ul>
|
||||
* <li>{@link org.hibernate.annotations.processing.Find @Find}
|
||||
* is used to generate finder methods using the Metamodel
|
||||
* Generator,
|
||||
* <li>{@link org.hibernate.annotations.processing.HQL @HQL}
|
||||
* and {@link org.hibernate.annotations.processing.SQL @SQL}
|
||||
* are used to generate query methods using the
|
||||
* Metamodel Generator, and
|
||||
* are used to generate query methods using the Metamodel
|
||||
* Generator, and
|
||||
* <li>{@link org.hibernate.annotations.processing.CheckHQL}
|
||||
* instructs the Query Validator to check all HQL queries
|
||||
* in the annotated package or type.
|
||||
* </ul>
|
||||
* <p>
|
||||
* Annotations in this package control Hibernate's compile-time
|
||||
* tooling. For example, this code defines a DAO-style repository
|
||||
* object:
|
||||
* <pre>
|
||||
* package org.example;
|
||||
*
|
||||
* import org.hibernate.StatelessSession;
|
||||
* import org.hibernate.annotations.processing.Find;
|
||||
* import org.hibernate.annotations.processing.HQL;
|
||||
* import org.hibernate.query.Order;
|
||||
*
|
||||
* import java.util.List;
|
||||
*
|
||||
* interface BookRepository {
|
||||
*
|
||||
* StatelessSession session();
|
||||
*
|
||||
* @Find
|
||||
* Book bookByIsbn(String isbn);
|
||||
*
|
||||
* @Find
|
||||
* List<Book> booksByPublisher(long publisher$id);
|
||||
*
|
||||
* @HQL("where title like :title")
|
||||
* List<Book> booksByTitle(String title, Order<Book> order);
|
||||
*
|
||||
* }
|
||||
* </pre>
|
||||
* <p>
|
||||
* The Metamodel Generator produces this implementation when
|
||||
* the interface is compiled:
|
||||
* <pre>
|
||||
* package org.example;
|
||||
*
|
||||
* import jakarta.annotation.Generated;
|
||||
* import jakarta.annotation.Nonnull;
|
||||
* import jakarta.enterprise.context.Dependent;
|
||||
* import jakarta.inject.Inject;
|
||||
* import jakarta.persistence.metamodel.StaticMetamodel;
|
||||
* import java.util.List;
|
||||
* import org.hibernate.StatelessSession;
|
||||
* import org.hibernate.query.Order;
|
||||
*
|
||||
* @Dependent
|
||||
* @StaticMetamodel(BookRepository.class)
|
||||
* @Generated("org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor")
|
||||
* public class BookRepository_ implements BookRepository {
|
||||
*
|
||||
*
|
||||
* @Override
|
||||
* public List<Book> booksByTitle(String title, Order<Book> order) {
|
||||
* return session.createQuery(BOOKS_BY_TITLE_String, Book.class)
|
||||
* .setParameter("title", title)
|
||||
* .setOrder(order)
|
||||
* .getResultList();
|
||||
* }
|
||||
*
|
||||
* @Override
|
||||
* public Book bookByIsbn(@Nonnull String isbn) {
|
||||
* return session.get(Book.class, isbn);
|
||||
* }
|
||||
*
|
||||
* private final @Nonnull StatelessSession session;
|
||||
*
|
||||
* @Inject
|
||||
* public BookRepository_(@Nonnull StatelessSession session) {
|
||||
* this.session = session;
|
||||
* }
|
||||
*
|
||||
* public @Nonnull StatelessSession session() {
|
||||
* return session;
|
||||
* }
|
||||
*
|
||||
* @Override
|
||||
* public List<Book> booksByPublisher(long publisher$id) {
|
||||
* var builder = session.getFactory().getCriteriaBuilder();
|
||||
* var query = builder.createQuery(Book.class);
|
||||
* var entity = query.from(Book.class);
|
||||
* query.where(
|
||||
* builder.equal(entity.get(Book_.publisher).get(Publisher_.id), publisher$id)
|
||||
* );
|
||||
* return session.createQuery(query).getResultList();
|
||||
* }
|
||||
*
|
||||
* static final String BOOKS_BY_TITLE_String = "where title like :title";
|
||||
*
|
||||
* }
|
||||
* </pre>
|
||||
* <p>
|
||||
* The exact annotations included in the generated code depend on
|
||||
* the libraries available during compilation. The code above was
|
||||
* produced with CDI and Jakarta annotations on the build path,
|
||||
* and so the repository is an injectable CDI bean and uses
|
||||
* {@code @Nonnull} to indicate required parameters.
|
||||
*/
|
||||
@Incubating
|
||||
package org.hibernate.annotations.processing;
|
||||
|
|
Loading…
Reference in New Issue