more misc cleanups

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-08-30 22:38:11 +02:00
parent ab12b436a2
commit 67bd785add
6 changed files with 14 additions and 19 deletions

View File

@ -68,7 +68,6 @@ import net.bytebuddy.jar.asm.Opcodes;
import net.bytebuddy.jar.asm.Type;
import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.matcher.ElementMatchers;
import net.bytebuddy.pool.TypePool;
import org.checkerframework.checker.nullness.qual.Nullable;
public class BytecodeProviderImpl implements BytecodeProvider {

View File

@ -27,8 +27,6 @@ import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.pretty.MessageHelper;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.type.AnyType;
import org.hibernate.type.AssociationType;
import org.hibernate.type.CollectionType;
@ -38,13 +36,11 @@ import org.hibernate.type.EntityType;
import org.hibernate.type.ForeignKeyDirection;
import org.hibernate.type.ManyToOneType;
import org.hibernate.type.OneToOneType;
import org.hibernate.type.OneToOneType;
import org.hibernate.type.Type;
import static org.hibernate.engine.internal.ManagedTypeHelper.isHibernateProxy;
import static org.hibernate.engine.spi.CascadingActions.CHECK_ON_FLUSH;
import static org.hibernate.pretty.MessageHelper.infoString;
import static org.hibernate.type.ForeignKeyDirection.TO_PARENT;
/**
* Delegate responsible for, in conjunction with the various
@ -364,10 +360,9 @@ public final class Cascade {
);
}
if ( type instanceof CollectionType
|| type instanceof OneToOneType && ( (OneToOneType) type ).getForeignKeyDirection() == ForeignKeyDirection.TO_PARENT ) {
if ( isForeignKeyToParent( type ) ) {
// If FK direction is to-parent, we must remove the orphan *before* the queued update(s)
// occur. Otherwise, replacing the association on a managed entity, without manually
// occur. Otherwise, replacing the association on a managed entity, without manually
// nulling and flushing, causes FK constraint violations.
eventSource.removeOrphanBeforeUpdates( entityName, loadedValue );
}
@ -381,6 +376,12 @@ public final class Cascade {
}
}
private static boolean isForeignKeyToParent(Type type) {
return type instanceof CollectionType
|| type instanceof OneToOneType
&& ((OneToOneType) type).getForeignKeyDirection() == ForeignKeyDirection.TO_PARENT;
}
/**
* Check if the association is a one to one in the logical model (either a shared-pk
* or unique fk).

View File

@ -889,7 +889,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
private Object removeProxyByKey(final EntityKey key) {
final EntityHolderImpl entityHolder;
if ( entitiesByKey != null && ( entityHolder = entitiesByKey.get( key ) ) != null ) {
Object proxy = entityHolder.proxy;
final Object proxy = entityHolder.proxy;
entityHolder.proxy = null;
return proxy;
}
@ -901,17 +901,16 @@ public class StatefulPersistenceContext implements PersistenceContext {
if ( !persister.hasProxy() ) {
return impl;
}
final Object proxy = getProxy( key );
return ( proxy != null ) ? narrowProxy( proxy, persister, key, impl ) : impl;
else {
final Object proxy = getProxy( key );
return proxy != null ? narrowProxy( proxy, persister, key, impl ) : impl;
}
}
@Override
public Object proxyFor(Object impl) throws HibernateException {
final EntityEntry e = getEntry( impl );
if ( e == null ) {
return impl;
}
return proxyFor( e.getPersister(), e.getEntityKey(), impl );
return e == null ? impl : proxyFor( e.getPersister(), e.getEntityKey(), impl );
}
@Override

View File

@ -33,7 +33,6 @@ import org.hibernate.boot.cfgxml.spi.LoadedConfig;
import org.hibernate.boot.cfgxml.spi.MappingReference;
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmHibernateMapping;
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmRootEntityType;
import org.hibernate.boot.jaxb.spi.JaxbBindableMappingDescriptor;
import org.hibernate.boot.jaxb.spi.Binding;
import org.hibernate.boot.model.TypeContributor;
import org.hibernate.boot.model.convert.internal.ClassBasedConverterDescriptor;

View File

@ -7,8 +7,6 @@
package org.hibernate.jpa.boot.internal;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Properties;

View File

@ -7,7 +7,6 @@
package org.hibernate.jpa.boot.spi;
import java.net.URL;
import java.util.Collection;
import java.util.List;
import java.util.Properties;
import jakarta.persistence.SharedCacheMode;