diff --git a/hibernate-core/src/main/java/org/hibernate/SessionFactory.java b/hibernate-core/src/main/java/org/hibernate/SessionFactory.java index dfc7ea87f2..5a7373a6e5 100644 --- a/hibernate-core/src/main/java/org/hibernate/SessionFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/SessionFactory.java @@ -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. *
+ * 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()}. + *
* 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. * *
+ * 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}. + *
* 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. diff --git a/hibernate-core/src/main/java/org/hibernate/SharedSessionContract.java b/hibernate-core/src/main/java/org/hibernate/SharedSessionContract.java index b28d37028f..eec3b10f60 100644 --- a/hibernate-core/src/main/java/org/hibernate/SharedSessionContract.java +++ b/hibernate-core/src/main/java/org/hibernate/SharedSessionContract.java @@ -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();