Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Two last things #10140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hibernate-core/src/main/java/org/hibernate/LockMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public enum LockMode implements FindOption, RefreshOption {
* <p>
* This lock mode is for internal use only and is not a legal
* argument to {@link Session#get(Class, Object, LockMode)},
* {@link Session#refresh(Object, LockMode)}, or
* {@link Session#refresh(Object, RefreshOption...)}, or
* {@link Session#lock(Object, LockMode)}. These methods throw
* an exception if {@code WRITE} is given as an argument.
* <p>
Expand Down
39 changes: 32 additions & 7 deletions hibernate-core/src/main/java/org/hibernate/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@
* behavior is appropriate for programs which use optimistic locking.
* <ul>
* <li>A different lock level may be obtained by explicitly specifying the mode using
* {@link #get(Class, Object, LockMode)}, {@link #find(Class, Object, LockModeType)},
* {@link #refresh(Object, LockMode)}, {@link #refresh(Object, LockModeType)}, or
* {@link org.hibernate.query.SelectionQuery#setLockMode(LockModeType)}.
* {@link #find(Class,Object,LockModeType)}, {@link #find(Class,Object,FindOption...)},
* {@link #refresh(Object,LockModeType)}, {@link #refresh(Object,RefreshOption...)},
* or {@link org.hibernate.query.SelectionQuery#setLockMode(LockModeType)}.
* <li>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)}.
Expand Down Expand Up @@ -802,7 +802,8 @@ public interface Session extends SharedSessionContract, EntityManager {
* with {@link jakarta.persistence.CascadeType#REFRESH}.
* <p>
* 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
*/
Expand Down Expand Up @@ -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> T get(Class<T> 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
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
16 changes: 6 additions & 10 deletions hibernate-core/src/main/java/org/hibernate/Timeouts.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
};
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,11 @@
return delegate.get( entityName, id, lockMode );
}

@Override
public <T> T get(Class<T> entityType, Object id, LockOptions lockOptions) {
return delegate.get( entityType, id, lockOptions );

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
Session.get
should be avoided because it has been deprecated.
}

@Override
public Object get(String entityName, Object id, LockOptions lockOptions) {
return delegate.get( entityName, id, lockOptions );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@

@Override
public Object get(String entityName, Object id) {
return this.lazySession.get().get( entityName, id );

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
Session.get
should be avoided because it has been deprecated.
}

@Override
Expand All @@ -296,6 +296,11 @@
return this.lazySession.get().get( entityName, id, lockMode );
}

@Override
public <T> T get(Class<T> 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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1174,17 +1174,22 @@ protected void releaseLoadEvent(LoadEvent event) {
}
}

@Override
@Override @Deprecated
public <T> T get(Class<T> 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> T get(Class<T> 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 );
}
Expand Down
3 changes: 1 addition & 2 deletions migration-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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`


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
11 changes: 11 additions & 0 deletions whats-new.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down