The lock level of a managed instance already held by the session may be upgraded
* to a more restrictive lock level by calling {@link #lock(Object, LockMode)} or
* {@link #lock(Object, LockModeType)}.
@@ -802,7 +802,8 @@ public interface Session extends SharedSessionContract, EntityManager {
* with {@link jakarta.persistence.CascadeType#REFRESH}.
*
* This operation requests {@link LockMode#READ}. To obtain a stronger lock,
- * call {@link #refresh(Object, LockMode)}.
+ * call {@link #refresh(Object, RefreshOption...)}, passing the appropriate
+ * {@link LockMode} as an option.
*
* @param object a persistent instance associated with this session
*/
@@ -938,6 +939,24 @@ public interface Session extends SharedSessionContract, EntityManager {
@Deprecated(since = "7.0", forRemoval = true)
Object get(String entityName, Object id, LockMode lockMode);
+ /**
+ * Return the persistent instance of the given entity class with the given identifier,
+ * or null if there is no such persistent instance. If the instance is already associated
+ * with the session, return that instance. This method never returns an uninitialized
+ * instance. Obtain the specified lock mode if the instance exists.
+ *
+ * @param entityType the entity type
+ * @param id an identifier
+ * @param lockOptions the lock mode
+ *
+ * @return a persistent instance or null
+ *
+ * @deprecated This method will be removed.
+ * Use {@link #find(Class, Object, FindOption...)} instead.
+ */
+ @Deprecated(since = "7.0", forRemoval = true)
+ T get(Class entityType, Object id, LockOptions lockOptions);
+
/**
* Return the persistent instance of the given entity class with the given identifier,
* or null if there is no such persistent instance. If the instance is already associated
@@ -950,7 +969,11 @@ public interface Session extends SharedSessionContract, EntityManager {
*
* @return a persistent instance or null
*
- * @deprecated Use {@linkplain #find(Class, Object, FindOption...)} instead
+ * @deprecated This method will be removed.
+ * Use {@link SessionFactory#createGraphForDynamicEntity(String)}
+ * together with {@link #find(EntityGraph, Object, FindOption...)}
+ * to load {@link org.hibernate.metamodel.RepresentationMode#MAP
+ * dynamic entities}.
*/
@Deprecated(since = "7.0", forRemoval = true)
Object get(String entityName, Object id, LockOptions lockOptions);
@@ -967,7 +990,8 @@ public interface Session extends SharedSessionContract, EntityManager {
*
* @since 6.2
*
- * @deprecated Use {@linkplain #lock(Object, LockModeType, LockOption...)} instead
+ * @deprecated This method will be removed.
+ * Use {@linkplain #lock(Object, LockModeType, LockOption...)} instead
*/
@Deprecated(since = "7.0", forRemoval = true)
void lock(Object object, LockOptions lockOptions);
@@ -979,7 +1003,8 @@ public interface Session extends SharedSessionContract, EntityManager {
* @param object a persistent instance associated with this session
* @param lockOptions contains the lock mode to use
*
- * @deprecated Use {@linkplain #refresh(Object, RefreshOption...)} instead
+ * @deprecated This method will be removed.
+ * Use {@linkplain #refresh(Object, RefreshOption...)} instead
*/
@Deprecated(since = "7.0", forRemoval = true)
void refresh(Object object, LockOptions lockOptions);
diff --git a/hibernate-core/src/main/java/org/hibernate/Timeouts.java b/hibernate-core/src/main/java/org/hibernate/Timeouts.java
index e5f1e32a1dab..a8850ca43633 100644
--- a/hibernate-core/src/main/java/org/hibernate/Timeouts.java
+++ b/hibernate-core/src/main/java/org/hibernate/Timeouts.java
@@ -65,16 +65,12 @@ public interface Timeouts {
* the "magic values".
*/
static Timeout interpretMilliSeconds(int timeoutInMilliseconds) {
- if ( timeoutInMilliseconds == NO_WAIT_MILLI ) {
- return NO_WAIT;
- }
- else if ( timeoutInMilliseconds == WAIT_FOREVER_MILLI ) {
- return WAIT_FOREVER;
- }
- else if ( timeoutInMilliseconds == SKIP_LOCKED_MILLI ) {
- return SKIP_LOCKED;
- }
- return Timeout.milliseconds( timeoutInMilliseconds );
+ return switch ( timeoutInMilliseconds ) {
+ case NO_WAIT_MILLI -> NO_WAIT;
+ case WAIT_FOREVER_MILLI -> WAIT_FOREVER;
+ case SKIP_LOCKED_MILLI -> SKIP_LOCKED;
+ default -> Timeout.milliseconds( timeoutInMilliseconds );
+ };
}
/**
diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java
index f04d30246f30..5b73af08a162 100644
--- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java
+++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java
@@ -982,6 +982,11 @@ public Object get(String entityName, Object id, LockMode lockMode) {
return delegate.get( entityName, id, lockMode );
}
+ @Override
+ public T get(Class entityType, Object id, LockOptions lockOptions) {
+ return delegate.get( entityType, id, lockOptions );
+ }
+
@Override
public Object get(String entityName, Object id, LockOptions lockOptions) {
return delegate.get( entityName, id, lockOptions );
diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionLazyDelegator.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionLazyDelegator.java
index dcebd8a82c9c..9223479b476a 100644
--- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionLazyDelegator.java
+++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionLazyDelegator.java
@@ -296,6 +296,11 @@ public Object get(String entityName, Object id, LockMode lockMode) {
return this.lazySession.get().get( entityName, id, lockMode );
}
+ @Override
+ public T get(Class entityType, Object id, LockOptions lockOptions) {
+ return this.lazySession.get().get( entityType, id, lockOptions );
+ }
+
@Override
public Object get(String entityName, Object id, LockOptions lockOptions) {
return this.lazySession.get().get( entityName, id, lockOptions );
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 5d18103cf189..c53d5bd29306 100644
--- a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java
+++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java
@@ -1174,17 +1174,22 @@ protected void releaseLoadEvent(LoadEvent event) {
}
}
- @Override
+ @Override @Deprecated
public T get(Class entityClass, Object id, LockMode lockMode) {
return this.byId( entityClass ).with( new LockOptions( lockMode ) ).load( id );
}
- @Override
+ @Override @Deprecated
public Object get(String entityName, Object id, LockMode lockMode) {
return this.byId( entityName ).with( new LockOptions( lockMode ) ).load( id );
}
- @Override
+ @Override @Deprecated
+ public T get(Class entityClass, Object id, LockOptions lockOptions) {
+ return this.byId( entityClass ).with( lockOptions ).load( id );
+ }
+
+ @Override @Deprecated
public Object get(String entityName, Object id, LockOptions lockOptions) {
return this.byId( entityName ).with( lockOptions ).load( id );
}
diff --git a/migration-guide.adoc b/migration-guide.adoc
index 3abc842d6cde..7eba87c8c3b4 100644
--- a/migration-guide.adoc
+++ b/migration-guide.adoc
@@ -259,7 +259,6 @@ Also, `LockAcquisitionException` now extends `PessimisticLockException`.
`Query#setOrder` was an incubating API added in support of Hibernate's Jakarta Data and Repositories implementations.
It was never a great solution and has been replaced with a better alternative - link:{whatsNewBase}#QuerySpecification[QuerySpecification].
-
[[misc-api]]
=== Miscellaneous
@@ -269,7 +268,7 @@ It was never a great solution and has been replaced with a better alternative -
* Removed `Session.LockRequest` - use `LockOptions` instead
* `SessionFactory.createEntityManager()` now returns `Session` for convenience
* `CommonQueryContract.setFlushMode()` was deprecated in favor of `setQueryFlushMode` accepting a `QueryFlushMode`
-
+* Incubating interfaces `BindableType`, `OutputableType`, and `BindingContext` were moved to `org.hibernate.type`
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/whats-new.adoc b/whats-new.adoc
index ee9583919926..3b41ee5fc9c3 100644
--- a/whats-new.adoc
+++ b/whats-new.adoc
@@ -231,6 +231,17 @@ This feature is considered incubating.
====
+[[metamode-param-binding]]
+== Use of metamodel in query parameter binding
+
+When an argument to a query parameter is of ambiguous type, the static metamodel may now be used to disambiguate.
+
+[source,java]
+session.createSelectionQuery("from Thing where uniqueKey = ?1")
+ .setParameter(1, key, Thing_.uniqueKey.getType())
+ .getSingleResult();
+
+
[[enum-checks]]
== Converted Enums and Check Constraints