Skip to content

use safe casts #2131

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 1 commit into from
Feb 20, 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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.hibernate.LockMode;
import org.hibernate.bytecode.enhance.spi.interceptor.EnhancementAsProxyLazinessInterceptor;
import org.hibernate.collection.spi.AbstractPersistentCollection;
import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
import org.hibernate.engine.spi.PersistentAttributeInterceptor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
Expand Down Expand Up @@ -2452,18 +2451,18 @@ static <T> Uni<T> fetch(T association) {
}

final SharedSessionContractImplementor session;
if ( association instanceof HibernateProxy ) {
session = ( (HibernateProxy) association ).getHibernateLazyInitializer().getSession();
if ( association instanceof HibernateProxy proxy ) {
session = proxy.getHibernateLazyInitializer().getSession();
}
else if ( association instanceof PersistentCollection ) {
else if ( association instanceof AbstractPersistentCollection<?> collection ) {
//this unfortunately doesn't work for stateless session because the session ref gets set to null
session = ( (AbstractPersistentCollection<?>) association ).getSession();
session = collection.getSession();
}
else if ( isPersistentAttributeInterceptable( association ) ) {
final PersistentAttributeInterceptable interceptable = asPersistentAttributeInterceptable( association );
final PersistentAttributeInterceptor interceptor = interceptable.$$_hibernate_getInterceptor();
if ( interceptor instanceof EnhancementAsProxyLazinessInterceptor ) {
session = ( (EnhancementAsProxyLazinessInterceptor) interceptor ).getLinkedSession();
if ( interceptor instanceof EnhancementAsProxyLazinessInterceptor lazinessInterceptor ) {
session = lazinessInterceptor.getLinkedSession();
}
else {
return Uni.createFrom().item( association );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.hibernate.LockMode;
import org.hibernate.bytecode.enhance.spi.interceptor.EnhancementAsProxyLazinessInterceptor;
import org.hibernate.collection.spi.AbstractPersistentCollection;
import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
import org.hibernate.engine.spi.PersistentAttributeInterceptor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
Expand Down Expand Up @@ -2499,17 +2498,17 @@ static <T> CompletionStage<T> fetch(T association) {
}

final SharedSessionContractImplementor session;
if ( association instanceof HibernateProxy) {
session = ( (HibernateProxy) association ).getHibernateLazyInitializer().getSession();
if ( association instanceof HibernateProxy proxy ) {
session = proxy.getHibernateLazyInitializer().getSession();
}
else if ( association instanceof PersistentCollection) {
session = ( (AbstractPersistentCollection<?>) association ).getSession();
else if ( association instanceof AbstractPersistentCollection<?> collection ) {
session = collection.getSession();
}
else if ( isPersistentAttributeInterceptable( association ) ) {
final PersistentAttributeInterceptable interceptable = asPersistentAttributeInterceptable( association );
final PersistentAttributeInterceptor interceptor = interceptable.$$_hibernate_getInterceptor();
if ( interceptor instanceof EnhancementAsProxyLazinessInterceptor) {
session = ( (EnhancementAsProxyLazinessInterceptor) interceptor ).getLinkedSession();
if ( interceptor instanceof EnhancementAsProxyLazinessInterceptor lazinessInterceptor) {
session = lazinessInterceptor.getLinkedSession();
}
else {
return CompletionStages.completedFuture( association );
Expand Down
Loading