change SessionFactory.getCriteriaBuilder() to return HibernateCriteriaBuilder

This commit is contained in:
Gavin 2022-12-27 14:20:08 +01:00 committed by Gavin King
parent d6b8ed710f
commit addb48fe82
2 changed files with 30 additions and 4 deletions

View File

@ -17,6 +17,7 @@ import javax.naming.Referenceable;
import org.hibernate.boot.spi.SessionFactoryOptions;
import org.hibernate.engine.spi.FilterDefinition;
import org.hibernate.graph.RootGraph;
import org.hibernate.query.criteria.HibernateCriteriaBuilder;
import org.hibernate.relational.SchemaManager;
import org.hibernate.stat.Statistics;
@ -36,6 +37,11 @@ import jakarta.persistence.EntityManagerFactory;
* obtain a new {@link Session} instance from the factory each time it services
* a client request.
* <p>
* The {@link #inSession} and {@link #inTransaction} methods provide a convenient
* way to obtain a session, with or without starting a transaction, and have it
* cleaned up automatically, relieving the program of the need to explicitly
* call {@link Session#close()} and {@link Transaction#commit()}.
* <p>
* Depending on how Hibernate is configured, the {@code SessionFactory} itself
* might be responsible for the lifecycle of pooled JDBC connections and
* transactions, or it may simply act as a client for a connection pool or
@ -84,6 +90,12 @@ import jakarta.persistence.EntityManagerFactory;
* cleaning up} data left behind by tests.
* </ul>
* <p>
* Finally, the factory {@linkplain #getCriteriaBuilder() provides} a
* {@link HibernateCriteriaBuilder}, an extension to the JPA-defined interface
* {@link jakarta.persistence.criteria.CriteriaBuilder}, which may be used to
* construct {@linkplain jakarta.persistence.criteria.CriteriaQuery criteria
* queries}.
* <p>
* Every {@code SessionFactory} is a JPA {@link EntityManagerFactory}.
* Furthermore, when Hibernate is acting as the JPA persistence provider, the
* method {@link EntityManagerFactory#unwrap(Class)} may be used to obtain the
@ -283,6 +295,17 @@ public interface SessionFactory extends EntityManagerFactory, Referenceable, Ser
*/
SchemaManager getSchemaManager();
/**
* Obtain a {@link HibernateCriteriaBuilder} which may be used to
* {@linkplain HibernateCriteriaBuilder#createQuery(Class) construct}
* {@linkplain org.hibernate.query.criteria.JpaCriteriaQuery criteria
* queries}.
*
* @see SharedSessionContract#getCriteriaBuilder()
*/
@Override
HibernateCriteriaBuilder getCriteriaBuilder();
/**
* Destroy this {@code SessionFactory} and release all its resources,
* including caches and connection pools.

View File

@ -9,8 +9,6 @@ package org.hibernate;
import java.io.Closeable;
import java.io.Serializable;
import jakarta.persistence.criteria.CriteriaBuilder;
import org.hibernate.jdbc.ReturningWork;
import org.hibernate.jdbc.Work;
import org.hibernate.procedure.ProcedureCall;
@ -181,11 +179,16 @@ public interface SharedSessionContract extends QueryProducer, Closeable, Seriali
void setJdbcBatchSize(Integer jdbcBatchSize);
/**
* Return an instance of {@link CriteriaBuilder}.
* Obtain a {@link HibernateCriteriaBuilder} which may be used to
* {@linkplain HibernateCriteriaBuilder#createQuery(Class) construct}
* {@linkplain org.hibernate.query.criteria.JpaCriteriaQuery criteria
* queries}.
*
* @return an instance of CriteriaBuilder
* @return an instance of {@link HibernateCriteriaBuilder}
*
* @throws IllegalStateException if the session has been closed
*
* @see SessionFactory#getCriteriaBuilder()
*/
HibernateCriteriaBuilder getCriteriaBuilder();