Skip to content

Commit ab15c87

Browse files
committed
fixed the unsoundness of the coerce() method
1 parent a0a09bf commit ab15c87

27 files changed

+105
-130
lines changed

hibernate-core/src/main/java/org/hibernate/cache/internal/DefaultCacheKeysFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static Object staticCreateEntityKey(Object id, EntityPersister persister,
6767

6868
private static Object getCoercedId(Object id, SessionFactoryImplementor factory, Type keyType) {
6969
return keyType instanceof BasicType<?> basicType
70-
? basicType.getJavaTypeDescriptor().coerce( id, factory::getTypeConfiguration )
70+
? basicType.getJavaTypeDescriptor().coerce( id )
7171
: id;
7272
}
7373

hibernate-core/src/main/java/org/hibernate/cache/internal/EnabledCaching.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public boolean containsEntity(String entityName, Object identifier) {
229229
if ( cacheAccess != null ) {
230230
final Object idValue =
231231
persister.getIdentifierMapping().getJavaType()
232-
.coerce( identifier, sessionFactory::getTypeConfiguration );
232+
.coerce( identifier );
233233
final Object key = cacheAccess.generateCacheKey(
234234
idValue,
235235
persister.getRootEntityDescriptor().getEntityPersister(),

hibernate-core/src/main/java/org/hibernate/loader/ast/internal/AbstractMultiIdEntityLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ private List<T> orderedMultiLoad(
161161
}
162162

163163
private Object coerce(SharedSessionContractImplementor session, JavaType<?> idType, Object id) {
164-
return idCoercionEnabled ? idType.coerce( id, session ) : id;
164+
return idCoercionEnabled ? idType.coerce( id ) : id;
165165
}
166166

167167
private static LockOptions lockOptions(MultiIdLoadOptions loadOptions) {

hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public static <K> K[] normalizeKeys(
188188
}
189189
else {
190190
for ( int i = 0; i < keys.length; i++ ) {
191-
typedArray[i] = keyJavaType.coerce( keys[i], session );
191+
typedArray[i] = keyJavaType.cast( keyJavaType.coerce( keys[i] ) );
192192
}
193193
}
194194
return typedArray;

hibernate-core/src/main/java/org/hibernate/loader/internal/IdentifierLoadAccessImpl.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
import org.hibernate.graph.GraphSemantic;
2727
import org.hibernate.graph.spi.RootGraphImplementor;
2828
import org.hibernate.persister.entity.EntityPersister;
29-
import org.hibernate.type.descriptor.java.JavaType;
30-
import org.hibernate.type.spi.TypeConfiguration;
3129

3230
import static org.hibernate.proxy.HibernateProxy.extractLazyInitializer;
3331

@@ -37,7 +35,7 @@
3735
* @author Steve Ebersole
3836
*/
3937
// Hibernate Reactive extends this class: see ReactiveIdentifierLoadAccessImpl
40-
public class IdentifierLoadAccessImpl<T> implements IdentifierLoadAccess<T>, JavaType.CoercionContext {
38+
public class IdentifierLoadAccessImpl<T> implements IdentifierLoadAccess<T> {
4139
private final LoadAccessContext context;
4240
private final EntityPersister entityPersister;
4341

@@ -199,7 +197,7 @@ protected Object coerceId(Object id, SessionFactoryImplementor factory) {
199197
final var identifierMapping = entityPersister.getIdentifierMapping();
200198
return identifierMapping.isVirtual()
201199
? id // special case for a class with an @IdClass
202-
: identifierMapping.getJavaType().coerce( id, this );
200+
: identifierMapping.getJavaType().coerce( id );
203201
}
204202
catch ( Exception e ) {
205203
throw new IllegalArgumentException( "Argument '" + id
@@ -233,11 +231,6 @@ private static boolean isLoadByIdComplianceEnabled(SessionFactoryImplementor fac
233231
return factory.getSessionFactoryOptions().getJpaCompliance().isLoadByIdComplianceEnabled();
234232
}
235233

236-
@Override
237-
public TypeConfiguration getTypeConfiguration() {
238-
return context.getSession().getSessionFactory().getTypeConfiguration();
239-
}
240-
241234
@Override
242235
public IdentifierLoadAccess<T> enableFetchProfile(String profileName) {
243236
if ( !context.getSession().getFactory().containsFetchProfileDefinition( profileName ) ) {

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleNaturalIdMapping.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,16 @@
3434
import org.hibernate.sql.results.graph.DomainResult;
3535
import org.hibernate.sql.results.graph.DomainResultCreationState;
3636
import org.hibernate.type.descriptor.java.JavaType;
37-
import org.hibernate.type.spi.TypeConfiguration;
3837

3938
import static org.hibernate.loader.ast.internal.MultiKeyLoadHelper.supportsSqlArrayType;
4039

4140
/**
4241
* Single-attribute NaturalIdMapping implementation
4342
*/
4443
public class SimpleNaturalIdMapping extends AbstractNaturalIdMapping
45-
implements JavaType.CoercionContext, BasicValuedMapping {
44+
implements BasicValuedMapping {
4645
private final SingularAttributeMapping attribute;
4746
private final SessionFactoryImplementor sessionFactory;
48-
private final TypeConfiguration typeConfiguration;
4947

5048
public SimpleNaturalIdMapping(
5149
SingularAttributeMapping attribute,
@@ -54,7 +52,6 @@ public SimpleNaturalIdMapping(
5452
super( declaringType, attribute.getAttributeMetadata().isUpdatable() );
5553
this.attribute = attribute;
5654
this.sessionFactory = creationProcess.getCreationContext().getSessionFactory();
57-
this.typeConfiguration = creationProcess.getCreationContext().getTypeConfiguration();
5855
}
5956

6057
public SingularAttributeMapping getAttribute() {
@@ -143,7 +140,7 @@ public Object normalizeInput(Object incoming) {
143140
final Object normalizedValue = normalizedValue( incoming );
144141
return isLoadByIdComplianceEnabled()
145142
? normalizedValue
146-
: getJavaType().coerce( normalizedValue, this );
143+
: getJavaType().coerce( normalizedValue );
147144
}
148145

149146
private Object normalizedValue(Object incoming) {
@@ -295,11 +292,6 @@ private Dialect getDialect() {
295292
return sessionFactory.getJdbcServices().getDialect();
296293
}
297294

298-
@Override
299-
public TypeConfiguration getTypeConfiguration() {
300-
return typeConfiguration;
301-
}
302-
303295
@Override
304296
public AttributeMapping asAttributeMapping() {
305297
return getAttribute();

hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterBindingImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*
3232
* @author Steve Ebersole
3333
*/
34-
public class QueryParameterBindingImpl<T> implements QueryParameterBinding<T>, JavaType.CoercionContext {
34+
public class QueryParameterBindingImpl<T> implements QueryParameterBinding<T> {
3535
private final QueryParameter<T> queryParameter;
3636
private final SessionFactoryImplementor sessionFactory;
3737

@@ -296,7 +296,6 @@ private void validate(Object value, TemporalType clarifiedTemporalType) {
296296
QueryParameterBindingValidator.INSTANCE.validate( getBindType(), value, clarifiedTemporalType, getCriteriaBuilder() );
297297
}
298298

299-
@Override
300299
public TypeConfiguration getTypeConfiguration() {
301300
return sessionFactory.getTypeConfiguration();
302301
}
@@ -337,7 +336,7 @@ private Object coerce(T value, BindableType<? super T> parameterType) {
337336
}
338337
else {
339338
return getCriteriaBuilder().resolveExpressible( parameterType )
340-
.getExpressibleJavaType().coerce( value, this );
339+
.getExpressibleJavaType().coerce( value );
341340
}
342341
}
343342

hibernate-core/src/main/java/org/hibernate/sql/results/graph/basic/CoercingResultAssembler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ public CoercingResultAssembler(
3030
@Override
3131
public Object extractRawValue(RowProcessingState rowProcessingState) {
3232
return assembledJavaType.coerce(
33-
super.extractRawValue( rowProcessingState ),
34-
rowProcessingState.getSession()
33+
super.extractRawValue( rowProcessingState )
3534
);
3635
}
3736
}

hibernate-core/src/main/java/org/hibernate/type/AbstractStandardBasicType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public final String toLoggableString(Object value, SessionFactoryImplementor fac
258258
|| !Hibernate.isInitialized( value )
259259
? "<uninitialized>"
260260
: javaType.extractLoggableRepresentation(
261-
javaType.coerce( value, factory::getTypeConfiguration ) );
261+
javaType.cast( javaType.coerce( value ) ) );
262262
}
263263

264264
@Override

hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ArrayJavaType.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ public boolean areEqual(Object[] one, Object[] another) {
128128
// Horrible hack around the fact that java.sql.Timestamps
129129
// can be represented as instances of java.util.Date
130130
// (Why do we even allow this? We deprecated java.sql stuff!)
131-
elementJavaType.coerce( one[i], null ),
132-
elementJavaType.coerce( another[i], null ) )) {
131+
elementJavaType.cast( elementJavaType.coerce( one[i] ) ),
132+
elementJavaType.cast( elementJavaType.coerce( another[i] ) ) ) ) {
133133
return false;
134134
}
135135
}
@@ -448,7 +448,7 @@ public T[] deepCopy(Object[] value) {
448448
// Horrible hack around the fact that java.sql.Timestamps
449449
// can be represented as instances of java.util.Date
450450
// (Why do we even allow this? We deprecated java.sql stuff!)
451-
baseDescriptor.coerce( value[i], null ) );
451+
baseDescriptor.cast( baseDescriptor.coerce( value[i] ) ) );
452452
}
453453
return copy;
454454
}

0 commit comments

Comments
 (0)