From 6215a8ef423e0a4b2737a3168cba4b246a76c684 Mon Sep 17 00:00:00 2001 From: Gavin Date: Tue, 23 May 2023 00:08:19 +0200 Subject: [PATCH] add some additional hints for EM.setProperty() --- .../org/hibernate/internal/SessionImpl.java | 24 ++++++++++- .../org/hibernate/jpa/HibernateHints.java | 43 +++++++++++++++++-- 2 files changed, 62 insertions(+), 5 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java index 163da8eabd..e25f8f275e 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java @@ -152,6 +152,7 @@ import static java.lang.System.currentTimeMillis; import static java.util.Collections.unmodifiableMap; import static org.hibernate.CacheMode.fromJpaModes; import static org.hibernate.cfg.AvailableSettings.CRITERIA_COPY_TREE; +import static org.hibernate.cfg.AvailableSettings.DEFAULT_BATCH_FETCH_SIZE; import static org.hibernate.cfg.AvailableSettings.JAKARTA_LOCK_SCOPE; import static org.hibernate.cfg.AvailableSettings.JAKARTA_LOCK_TIMEOUT; import static org.hibernate.cfg.AvailableSettings.JAKARTA_SHARED_CACHE_RETRIEVE_MODE; @@ -160,10 +161,16 @@ import static org.hibernate.cfg.AvailableSettings.JPA_LOCK_SCOPE; import static org.hibernate.cfg.AvailableSettings.JPA_LOCK_TIMEOUT; import static org.hibernate.cfg.AvailableSettings.JPA_SHARED_CACHE_RETRIEVE_MODE; import static org.hibernate.cfg.AvailableSettings.JPA_SHARED_CACHE_STORE_MODE; +import static org.hibernate.cfg.AvailableSettings.STATEMENT_BATCH_SIZE; +import static org.hibernate.cfg.AvailableSettings.USE_SUBSELECT_FETCH; import static org.hibernate.event.spi.LoadEventListener.IMMEDIATE_LOAD; import static org.hibernate.event.spi.LoadEventListener.INTERNAL_LOAD_EAGER; import static org.hibernate.event.spi.LoadEventListener.INTERNAL_LOAD_LAZY; import static org.hibernate.event.spi.LoadEventListener.INTERNAL_LOAD_NULLABLE; +import static org.hibernate.jpa.HibernateHints.HINT_BATCH_FETCH_SIZE; +import static org.hibernate.jpa.HibernateHints.HINT_ENABLE_SUBSELECT_FETCH; +import static org.hibernate.jpa.HibernateHints.HINT_FETCH_PROFILE; +import static org.hibernate.jpa.HibernateHints.HINT_JDBC_BATCH_SIZE; import static org.hibernate.jpa.HibernateHints.HINT_READ_ONLY; import static org.hibernate.jpa.HibernateHints.HINT_FLUSH_MODE; import static org.hibernate.jpa.LegacySpecHints.HINT_JAVAEE_LOCK_TIMEOUT; @@ -2697,7 +2704,7 @@ public class SessionImpl private void interpretProperty(String propertyName, Object value) { switch ( propertyName ) { case HINT_FLUSH_MODE: - setHibernateFlushMode( ConfigurationHelper.getFlushMode(value, FlushMode.AUTO) ); + setHibernateFlushMode( ConfigurationHelper.getFlushMode( value, FlushMode.AUTO ) ); break; case JPA_LOCK_SCOPE: case JAKARTA_LOCK_SCOPE: @@ -2736,6 +2743,21 @@ public class SessionImpl case CRITERIA_COPY_TREE: setCriteriaCopyTreeEnabled( parseBoolean( value.toString() ) ); break; + case HINT_FETCH_PROFILE: + enableFetchProfile( (String) value ); + break; + case USE_SUBSELECT_FETCH: + case HINT_ENABLE_SUBSELECT_FETCH: + setSubselectFetchingEnabled( Boolean.parseBoolean( value.toString() ) ); + break; + case DEFAULT_BATCH_FETCH_SIZE: + case HINT_BATCH_FETCH_SIZE: + setFetchBatchSize( Integer.parseInt( value.toString() ) ); + break; + case STATEMENT_BATCH_SIZE: + case HINT_JDBC_BATCH_SIZE: + setJdbcBatchSize( Integer.parseInt( value.toString() ) ); + break; } } diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/HibernateHints.java b/hibernate-core/src/main/java/org/hibernate/jpa/HibernateHints.java index 2ae379409e..ad437f682b 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/HibernateHints.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/HibernateHints.java @@ -6,8 +6,6 @@ */ package org.hibernate.jpa; -import jakarta.persistence.EntityManagerFactory; - /** * List of Hibernate-specific (extension) hints available to query, * load, and lock scenarios. @@ -160,10 +158,47 @@ public interface HibernateHints { String HINT_CALLABLE_FUNCTION = "org.hibernate.callableFunction"; /** - * Hint for specifying the tenant-id to use when creating an - * {@linkplain EntityManagerFactory#createEntityManager(java.util.Map) EntityManager}. + * Hint for specifying the tenant id to use when creating an + * {@link jakarta.persistence.EntityManagerFactory#createEntityManager(java.util.Map) EntityManager}. * * @see org.hibernate.SessionBuilder#tenantIdentifier + * @see jakarta.persistence.EntityManagerFactory#createEntityManager(java.util.Map) */ String HINT_TENANT_ID = "org.hibernate.tenantId"; + + /** + * Hint to enable a fetch profile for a given + * {@link jakarta.persistence.EntityManager#setProperty(String, Object) EntityManager}. + * + * @see org.hibernate.Session#enableFetchProfile(String) + * @see jakarta.persistence.EntityManager#setProperty(String, Object) + */ + String HINT_FETCH_PROFILE = "org.hibernate.fetchProfile"; + + /** + * Hint to enable subselect fetching for a given + * {@link jakarta.persistence.EntityManager#setProperty(String, Object) EntityManager}. + * + * @see org.hibernate.cfg.AvailableSettings#USE_SUBSELECT_FETCH + * @see jakarta.persistence.EntityManager#setProperty(String, Object) + */ + String HINT_ENABLE_SUBSELECT_FETCH = "org.hibernate.enableSubselectFetch"; + + /** + * Hint to set the batch size for batch fetching for a given + * {@link jakarta.persistence.EntityManager#setProperty(String, Object) EntityManager}. + * + * @see org.hibernate.cfg.AvailableSettings#DEFAULT_BATCH_FETCH_SIZE + * @see jakarta.persistence.EntityManager#setProperty(String, Object) + */ + String HINT_BATCH_FETCH_SIZE = "org.hibernate.batchFetchSize"; + + /** + * Hint to set the batch size for JDBC batching for a given + * {@link jakarta.persistence.EntityManager#setProperty(String, Object) EntityManager}. + * + * @see org.hibernate.cfg.AvailableSettings#STATEMENT_BATCH_SIZE + * @see jakarta.persistence.EntityManager#setProperty(String, Object) + */ + String HINT_JDBC_BATCH_SIZE = "org.hibernate.jdbcBatchSize"; }