diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryDelegatingImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryDelegatingImpl.java index b8eb35134f..2804b20c34 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryDelegatingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryDelegatingImpl.java @@ -433,7 +433,7 @@ public class SessionFactoryDelegatingImpl implements SessionFactoryImplementor, } @Override - public BindableType resolveParameterBindType(T bindValue) { + public BindableType resolveParameterBindType(T bindValue) { return delegate.resolveParameterBindType( bindValue ); } diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java index b2f46a2b92..28e83c221a 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java @@ -109,7 +109,6 @@ import org.hibernate.persister.entity.SessionFactoryBasedWrapperOptions; import org.hibernate.procedure.spi.ProcedureCallImplementor; import org.hibernate.proxy.EntityNotFoundDelegate; import org.hibernate.proxy.HibernateProxy; -import org.hibernate.proxy.HibernateProxyHelper; import org.hibernate.proxy.LazyInitializer; import org.hibernate.query.QueryLogging; import org.hibernate.query.hql.spi.SqmQueryImplementor; @@ -1084,14 +1083,24 @@ public class SessionFactoryImpl implements SessionFactoryImplementor { return fetchProfiles.get( name ); } - @Override - public BindableType resolveParameterBindType(T bindValue) { + @Override @SuppressWarnings("unchecked") + public BindableType resolveParameterBindType(T bindValue) { if ( bindValue == null ) { // we can't guess return null; } - return resolveParameterBindType( HibernateProxyHelper.getClassWithoutInitializingProxy( bindValue ) ); + Class clazz; + if (bindValue instanceof HibernateProxy) { + HibernateProxy proxy = (HibernateProxy) bindValue; + LazyInitializer li = proxy.getHibernateLazyInitializer(); + clazz = li.getPersistentClass(); + } + else { + clazz = (Class) bindValue.getClass(); + } + + return resolveParameterBindType( clazz ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/JpaMetamodel.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/JpaMetamodel.java index 32bc4f8ca1..5c872625e9 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/JpaMetamodel.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/JpaMetamodel.java @@ -9,7 +9,6 @@ package org.hibernate.metamodel.model.domain; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.function.Consumer; import jakarta.persistence.metamodel.EmbeddableType; import jakarta.persistence.metamodel.EntityType; import jakarta.persistence.metamodel.ManagedType; diff --git a/hibernate-core/src/main/java/org/hibernate/proxy/HibernateProxyHelper.java b/hibernate-core/src/main/java/org/hibernate/proxy/HibernateProxyHelper.java deleted file mode 100644 index edb504fde8..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/proxy/HibernateProxyHelper.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.proxy; - - - -/** - * Utility methods for working with proxies. (this class is being phased out) - * @author Gavin King - */ -public final class HibernateProxyHelper { - - /** - * Get the class of an instance or the underlying class - * of a proxy (without initializing the proxy!). It is - * almost always better to use the entity name! - */ - @SuppressWarnings("unchecked") - public static Class getClassWithoutInitializingProxy(T object) { - if (object instanceof HibernateProxy) { - HibernateProxy proxy = (HibernateProxy) object; - LazyInitializer li = proxy.getHibernateLazyInitializer(); - return li.getPersistentClass(); - } - else { - return (Class) object.getClass(); - } - } - - private HibernateProxyHelper() { - //cant instantiate - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/query/IllegalSelectQueryException.java b/hibernate-core/src/main/java/org/hibernate/query/IllegalSelectQueryException.java index 841773a03a..0ecfb1a4ac 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/IllegalSelectQueryException.java +++ b/hibernate-core/src/main/java/org/hibernate/query/IllegalSelectQueryException.java @@ -9,10 +9,8 @@ package org.hibernate.query; import org.hibernate.QueryException; /** - * Indicates an attempt to call {@link QueryProducer#createSelectQuery(String)}, - * {@link QueryProducer#name(String)} or - * {@link QueryProducer#createNativeMutationQuery(String)} with a non-mutation - * query (generally a select query) + * Indicates an attempt to call {@link QueryProducer#createSelectQuery(String)} + * with a non-selection query (generally a mutation query) * * @author Steve Ebersole */ diff --git a/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterBindingImpl.java b/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterBindingImpl.java index eeb3fbdeed..2d566ab78c 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterBindingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterBindingImpl.java @@ -37,7 +37,7 @@ public class QueryParameterBindingImpl implements QueryParameterBinding, J private boolean isBound; private boolean isMultiValued; - private BindableType bindType; + private BindableType bindType; private MappingModelExpressable type; private TemporalType explicitTemporalPrecision; @@ -68,7 +68,7 @@ public class QueryParameterBindingImpl implements QueryParameterBinding, J } @Override - public BindableType getBindType() { + public BindableType getBindType() { return bindType; } @@ -135,12 +135,12 @@ public class QueryParameterBindingImpl implements QueryParameterBinding, J bindValue( value ); } - private T coerce(T value, BindableType parameterType) { + private T coerce(T value, BindableType parameterType) { if ( value == null ) { return null; } - final SqmExpressable sqmExpressable = parameterType.resolveExpressable( sessionFactory ); + final SqmExpressable sqmExpressable = parameterType.resolveExpressable( sessionFactory ); assert sqmExpressable != null; return sqmExpressable.getExpressableJavaType().coerce( value, this ); @@ -301,8 +301,8 @@ public class QueryParameterBindingImpl implements QueryParameterBinding, J this.explicitTemporalPrecision = temporalTypePrecision; } - private JavaType determineJavaType(BindableType bindType) { - final SqmExpressable sqmExpressable = bindType.resolveExpressable( sessionFactory ); + private JavaType determineJavaType(BindableType bindType) { + final SqmExpressable sqmExpressable = bindType.resolveExpressable( sessionFactory ); assert sqmExpressable != null; return sqmExpressable.getExpressableJavaType(); diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterBinding.java b/hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterBinding.java index 1c929082d0..b5148af23f 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterBinding.java @@ -39,7 +39,7 @@ public interface QueryParameterBinding { * * @return The currently associated Type */ - BindableType getBindType(); + BindableType getBindType(); /** * If the parameter represents a temporal type, return the explicitly diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterBindingTypeResolver.java b/hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterBindingTypeResolver.java index 2b9360246a..6f98cbae16 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterBindingTypeResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/QueryParameterBindingTypeResolver.java @@ -16,7 +16,7 @@ import org.hibernate.type.spi.TypeConfiguration; * @author Steve Ebersole */ public interface QueryParameterBindingTypeResolver { - BindableType resolveParameterBindType(T bindValue); + BindableType resolveParameterBindType(T bindValue); BindableType resolveParameterBindType(Class clazz); TypeConfiguration getTypeConfiguration(); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java index 9fdfe0acac..49d9d23b42 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java @@ -714,7 +714,6 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, } @Override - @SuppressWarnings({ "unchecked", "rawtypes" }) public SqmExpression sum(Expression x, N y) { return createSqmArithmeticNode( BinaryArithmeticOperator.ADD, @@ -724,7 +723,6 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, } @Override - @SuppressWarnings({ "unchecked", "rawtypes" }) public SqmExpression sum(N x, Expression y) { return createSqmArithmeticNode( BinaryArithmeticOperator.ADD, @@ -770,11 +768,10 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, } @Override - @SuppressWarnings({ "unchecked", "rawtypes" }) public SqmExpression diff(Expression x, N y) { return createSqmArithmeticNode( BinaryArithmeticOperator.SUBTRACT, - (SqmExpression) x, + (SqmExpression) x, value( y ) ); } @@ -894,8 +891,8 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return new SqmLiteralNull<>( this ); } - final SqmExpressable expressable = resolveInferredType( value, typeInferenceSource, getTypeConfiguration() ); - return new SqmLiteral<>( value, expressable, this ); + final SqmExpressable expressible = resolveInferredType( value, typeInferenceSource, getTypeConfiguration() ); + return new SqmLiteral<>( value, expressible, this ); } private static SqmExpressable resolveInferredType( @@ -924,10 +921,10 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, return new SqmLiteralNull<>( this ); } - final BindableType valueParamType = queryEngine.getTypeConfiguration() + final BindableType valueParamType = queryEngine.getTypeConfiguration() .getSessionFactory() .resolveParameterBindType( value ); - final SqmExpressable sqmExpressable = valueParamType == null + final SqmExpressable sqmExpressable = valueParamType == null ? null : valueParamType.resolveExpressable( getTypeConfiguration().getSessionFactory() ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/AbstractSqmExpression.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/AbstractSqmExpression.java index 57ce94ec86..850b8a9b2b 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/AbstractSqmExpression.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/AbstractSqmExpression.java @@ -29,7 +29,7 @@ import static org.hibernate.query.internal.QueryHelper.highestPrecedenceType; */ public abstract class AbstractSqmExpression extends AbstractJpaSelection implements SqmExpression { - public AbstractSqmExpression(SqmExpressable type, NodeBuilder criteriaBuilder) { + public AbstractSqmExpression(SqmExpressable type, NodeBuilder criteriaBuilder) { super( type, criteriaBuilder ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmLiteral.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmLiteral.java index b738c27bdc..5709acd318 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmLiteral.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmLiteral.java @@ -25,7 +25,7 @@ import org.hibernate.type.descriptor.java.JavaType; public class SqmLiteral extends AbstractSqmExpression { private final T value; - public SqmLiteral(T value, SqmExpressable inherentType, NodeBuilder nodeBuilder) { + public SqmLiteral(T value, SqmExpressable inherentType, NodeBuilder nodeBuilder) { super( inherentType, nodeBuilder ); assert value != null; this.value = value; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/jpa/AbstractJpaSelection.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/jpa/AbstractJpaSelection.java index 1e2176cf2b..04af19ba5c 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/jpa/AbstractJpaSelection.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/jpa/AbstractJpaSelection.java @@ -21,7 +21,7 @@ import org.hibernate.query.sqm.tree.select.SqmSelectableNode; public abstract class AbstractJpaSelection extends AbstractJpaTupleElement implements SqmSelectableNode, JpaSelection { - protected AbstractJpaSelection(SqmExpressable sqmExpressable, NodeBuilder criteriaBuilder) { + protected AbstractJpaSelection(SqmExpressable sqmExpressable, NodeBuilder criteriaBuilder) { super( sqmExpressable, criteriaBuilder ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/jpa/AbstractJpaTupleElement.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/jpa/AbstractJpaTupleElement.java index 466aa57e60..7c4769db3c 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/jpa/AbstractJpaTupleElement.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/jpa/AbstractJpaTupleElement.java @@ -25,7 +25,7 @@ public abstract class AbstractJpaTupleElement private String alias; @SuppressWarnings("WeakerAccess") - protected AbstractJpaTupleElement(SqmExpressable expressableType, NodeBuilder criteriaBuilder) { + protected AbstractJpaTupleElement(SqmExpressable expressableType, NodeBuilder criteriaBuilder) { super( criteriaBuilder ); setExpressableType( expressableType ); diff --git a/hibernate-core/src/main/java/org/hibernate/type/AnyType.java b/hibernate-core/src/main/java/org/hibernate/type/AnyType.java index 6889bad6df..6969557fdf 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/AnyType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/AnyType.java @@ -9,7 +9,6 @@ package org.hibernate.type; import java.io.Serializable; import java.lang.reflect.Method; import java.sql.PreparedStatement; -import java.sql.ResultSet; import java.sql.SQLException; import java.util.Arrays; import java.util.Map; @@ -34,7 +33,6 @@ import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.Joinable; import org.hibernate.pretty.MessageHelper; import org.hibernate.proxy.HibernateProxy; -import org.hibernate.proxy.HibernateProxyHelper; import org.hibernate.proxy.LazyInitializer; import org.hibernate.type.spi.TypeConfiguration; @@ -265,11 +263,13 @@ public class AnyType extends AbstractType implements CompositeType, AssociationT } if ( value == LazyPropertyInitializer.UNFETCHED_PROPERTY || !Hibernate.isInitialized( value ) ) { - return ""; + return ""; } - final Class valueClass = HibernateProxyHelper.getClassWithoutInitializingProxy( value ); - final EntityPersister descriptor = factory.getDomainModel().getEntityDescriptor( valueClass ); + String entityName = factory.bestGuessEntityName(value); + final EntityPersister descriptor = entityName == null + ? null + : factory.getDomainModel().getEntityDescriptor( entityName ); return MessageHelper.infoString( descriptor, value, factory ); } @@ -309,10 +309,6 @@ public class AnyType extends AbstractType implements CompositeType, AssociationT } } - private Object nullSafeGet(ResultSet rs, String name, SharedSessionContractImplementor session, Object owner) { - throw new UnsupportedOperationException( "object is a multicolumn type" ); - } - // CompositeType implementation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @Override diff --git a/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/integration/manytoone/unidirectional/RelationNotAuditedTarget.java b/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/integration/manytoone/unidirectional/RelationNotAuditedTarget.java index f257e27b6f..075cbde180 100644 --- a/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/integration/manytoone/unidirectional/RelationNotAuditedTarget.java +++ b/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/integration/manytoone/unidirectional/RelationNotAuditedTarget.java @@ -16,8 +16,8 @@ import org.hibernate.orm.test.envers.Priority; import org.hibernate.orm.test.envers.entities.UnversionedStrTestEntity; import org.hibernate.orm.test.envers.entities.manytoone.unidirectional.TargetNotAuditedEntity; import org.hibernate.proxy.HibernateProxy; -import org.hibernate.proxy.HibernateProxyHelper; +import org.hibernate.proxy.LazyInitializer; import org.junit.Test; /** @@ -113,6 +113,17 @@ public class RelationNotAuditedTarget extends BaseEnversJPAFunctionalTestCase { assert Arrays.asList( 1, 2, 3, 4 ).equals( revisions ); } + static Class getClassWithoutInitializingProxy(Object object) { + if (object instanceof HibernateProxy) { + HibernateProxy proxy = (HibernateProxy) object; + LazyInitializer li = proxy.getHibernateLazyInitializer(); + return li.getPersistentClass(); + } + else { + return object.getClass(); + } + } + @Test public void testHistoryOfTnae1_id() { // load original "tnae1" TargetNotAuditedEntity to force load "str1" UnversionedStrTestEntity as Proxy @@ -133,7 +144,7 @@ public class RelationNotAuditedTarget extends BaseEnversJPAFunctionalTestCase { assert original.getReference() instanceof HibernateProxy; assert UnversionedStrTestEntity.class.equals( Hibernate.getClass( original.getReference() ) ); - assert UnversionedStrTestEntity.class.equals( HibernateProxyHelper.getClassWithoutInitializingProxy( rev1.getReference() ) ); + assert UnversionedStrTestEntity.class.equals( getClassWithoutInitializingProxy( rev1.getReference() ) ); assert UnversionedStrTestEntity.class.equals( Hibernate.getClass( rev1.getReference() ) ); }