Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -1767,7 +1767,7 @@ private void processValueResolvers(MetadataBuildingContext buildingContext) {

private void processSecondPasses(ArrayList<? extends SecondPass> secondPasses) {
if ( secondPasses != null ) {
for ( SecondPass secondPass : secondPasses ) {
for ( var secondPass : secondPasses ) {
secondPass.doSecondPass( getEntityBindingMap() );
}
secondPasses.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,13 +501,13 @@ private <T> void appendListeners(
EventType<T> eventType) {
final var eventListenerGroup = eventListenerRegistry.getEventListenerGroup( eventType );
for ( String listenerImpl : splitAtCommas( listeners ) ) {
@SuppressWarnings("unchecked")
T listener = (T) instantiate( listenerImpl, classLoaderService );
if ( !eventType.baseListenerInterface().isInstance( listener ) ) {
final var listener = instantiate( listenerImpl, classLoaderService );
final var baseListenerInterface = eventType.baseListenerInterface();
if ( !baseListenerInterface.isInstance( listener ) ) {
throw new HibernateException( "Event listener '" + listenerImpl
+ "' must implement '" + eventType.baseListenerInterface().getName() + "'");
+ "' must implement '" + baseListenerInterface.getName() + "'");
}
eventListenerGroup.appendListener( listener );
eventListenerGroup.appendListener( baseListenerInterface.cast( listener ) );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ private void transferImports() {
if ( !hbmImports.isEmpty() ) {
final var ormRoot = mappingXmlBinding.getRoot();
for ( var hbmImport : hbmImports ) {
final JaxbHqlImportImpl ormImport = new JaxbHqlImportImpl();
final var ormImport = new JaxbHqlImportImpl();
ormRoot.getHqlImports().add( ormImport );
ormImport.setClazz( hbmImport.getClazz() );
ormImport.setRename( hbmImport.getRename() );
Expand Down Expand Up @@ -890,7 +890,8 @@ private static JaxbNamedHqlQueryImpl transformNamedQuery(JaxbHbmNamedQueryType h
query.setQuery( qryString );
}
else {
@SuppressWarnings("unchecked") final var element = (JAXBElement<JaxbHbmQueryParamType>) content;
@SuppressWarnings("unchecked")
final var element = (JAXBElement<JaxbHbmQueryParamType>) content;
final var hbmQueryParam = element.getValue();
final var queryParam = new JaxbQueryParamTypeImpl();
query.getQueryParam().add( queryParam );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,23 @@ public static <X,Y> ConverterDescriptor<X,Y> of(
Class<? extends AttributeConverter<? extends X, ? extends Y>> converterClass,
Boolean autoApply, boolean overrideable, ClassmateContext classmateContext) {
@SuppressWarnings("unchecked") // work around weird fussiness in wildcard capture
final Class<? extends AttributeConverter<X, Y>> converterType =
(Class<? extends AttributeConverter<X, Y>>) converterClass;
final var converterType = (Class<? extends AttributeConverter<X, Y>>) converterClass;
return new ClassBasedConverterDescriptor<>( converterType, autoApply, classmateContext, overrideable );
}

public static <X,Y> ConverterDescriptor<X,Y> of(
Class<? extends AttributeConverter<? extends X, ? extends Y>> converterClass,
ClassmateContext classmateContext) {
@SuppressWarnings("unchecked") // work around weird fussiness in wildcard capture
final Class<? extends AttributeConverter<X, Y>> converterType =
(Class<? extends AttributeConverter<X, Y>>) converterClass;
final var converterType = (Class<? extends AttributeConverter<X, Y>>) converterClass;
return new ClassBasedConverterDescriptor<>( converterType, null, classmateContext, false );
}

public static <X,Y> ConverterDescriptor<X,Y> of(
Class<? extends AttributeConverter<? extends X, ? extends Y>> converterType,
ResolvedType domainTypeToMatch, ResolvedType relationalType, boolean autoApply) {
@SuppressWarnings("unchecked") // work around weird fussiness in wildcard capture
final Class<? extends AttributeConverter<X, Y>> converterClass =
(Class<? extends AttributeConverter<X, Y>>) converterType;
final var converterClass = (Class<? extends AttributeConverter<X, Y>>) converterType;
return new ConverterDescriptorImpl<>( converterClass, domainTypeToMatch, relationalType, autoApply );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static HashMap<String, String> extractParameterMap(Parameter[] parameters

public static JdbcMapping resolveUserType(Class<UserType<?>> userTypeClass, MetadataBuildingContext context) {
final var bootstrapContext = context.getBootstrapContext();
final UserType<?> userType =
final var userType =
context.getBuildingOptions().isAllowExtensionsInCdi()
? bootstrapContext.getManagedBeanRegistry().getBean( userTypeClass ).getBeanInstance()
: FallbackBeanInstanceProducer.INSTANCE.produceBeanInstance( userTypeClass );
Expand Down Expand Up @@ -74,7 +74,7 @@ public static <X,Y> JdbcMapping resolveAttributeConverter(

public static BasicType<?> resolveBasicType(Class<?> type, MetadataBuildingContext context) {
final var typeConfiguration = context.getBootstrapContext().getTypeConfiguration();
final JavaType<?> jtd = typeConfiguration.getJavaTypeRegistry().findDescriptor( type );
final var jtd = typeConfiguration.getJavaTypeRegistry().findDescriptor( type );
if ( jtd != null ) {
final JdbcType jdbcType = jtd.getRecommendedJdbcType(
new JdbcTypeIndicators() {
Expand Down Expand Up @@ -132,7 +132,7 @@ private static JavaType<?> getJavaType(
Class<JavaType<?>> javaTypeClass,
MetadataBuildingContext context,
TypeConfiguration typeConfiguration) {
final JavaType<?> registeredJtd =
final var registeredJtd =
typeConfiguration.getJavaTypeRegistry()
.findDescriptor( javaTypeClass );
if ( registeredJtd != null ) {
Expand All @@ -143,8 +143,7 @@ else if ( !context.getBuildingOptions().isAllowExtensionsInCdi() ) {
}
else {
return context.getBootstrapContext().getManagedBeanRegistry()
.getBean( javaTypeClass )
.getBeanInstance();
.getBean( javaTypeClass ).getBeanInstance();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.hibernate.AssertionFailure;
import org.hibernate.PropertyNotFoundException;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.boot.spi.SecondPass;
import org.hibernate.mapping.Collection;
import org.hibernate.mapping.Component;
import org.hibernate.mapping.IndexedCollection;
Expand Down Expand Up @@ -312,29 +311,25 @@ static void prepareActualProperty(
if ( !allowCollections ) {
throw new AssertionFailure( "Collections are not allowed as identifier properties" );
}
// The owner is a MappedSuperclass which is not a PersistentClass, so set it to null
// collection.setOwner( null );
// The owner is a MappedSuperclass, not a PersistentClass,
// so set it to null collection.setOwner( null );
collection.setRole( memberDetails.getDeclaringType().getName() + "." + property.getName() );
// To copy the element and key values, we need to defer setting the type name until the CollectionBinder ran
final var originalValue = property.getValue();
context.getMetadataCollector().addSecondPass(
new SecondPass() {
@Override
public void doSecondPass(Map<String, PersistentClass> persistentClasses) {
final var initializedCollection = (Collection) originalValue;
final var element = initializedCollection.getElement().copy();
setTypeName( element, memberDetails.getElementType().getName() );
if ( initializedCollection instanceof IndexedCollection indexedCollection ) {
final var index = indexedCollection.getIndex().copy();
if ( memberDetails.getMapKeyType() != null ) {
setTypeName( index, memberDetails.getMapKeyType().getName() );
}
( (IndexedCollection) collection ).setIndex( index );
}
collection.setElement( element );
}
context.getMetadataCollector().addSecondPass( persistentClasses -> {
final var initializedCollection = (Collection) originalValue;
final var element = initializedCollection.getElement().copy();
setTypeName( element, memberDetails.getElementType().getName() );
if ( initializedCollection instanceof IndexedCollection indexedCollection ) {
final var index = indexedCollection.getIndex().copy();
final var mapKeyType = memberDetails.getMapKeyType();
if ( mapKeyType != null ) {
setTypeName( index, mapKeyType.getName() );
}
);
( (IndexedCollection) collection ).setIndex( index );
}
collection.setElement( element );
} );
}
else {
setTypeName( value, memberDetails.getType().getName() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import jakarta.persistence.NamedAttributeNode;
import jakarta.persistence.NamedEntityGraph;
import jakarta.persistence.NamedSubgraph;
import org.hibernate.AnnotationException;
import org.hibernate.boot.model.NamedGraphCreator;
import org.hibernate.graph.internal.RootGraphImpl;
Expand Down Expand Up @@ -41,23 +40,23 @@ public <T> RootGraphImplementor<T> createEntityGraph(
Function<Class<T>, EntityDomainType<?>> entityDomainClassResolver,
Function<String, EntityDomainType<?>> entityDomainNameResolver) {
//noinspection unchecked
final EntityDomainType<T> rootEntityType =
(EntityDomainType<T>) entityDomainNameResolver.apply( jpaEntityName );
final RootGraphImplementor<T> entityGraph =
final var rootEntityType =
(EntityDomainType<T>)
entityDomainNameResolver.apply( jpaEntityName );
final var entityGraph =
createRootGraph( name, rootEntityType, annotation.includeAllAttributes() );

if ( annotation.subclassSubgraphs() != null ) {
for ( NamedSubgraph subclassSubgraph : annotation.subclassSubgraphs() ) {
final Class<?> subgraphType = subclassSubgraph.type();
final Class<T> graphJavaType = entityGraph.getGraphedType().getJavaType();
final var subclassSubgraphs = annotation.subclassSubgraphs();
if ( subclassSubgraphs != null ) {
for ( var subclassSubgraph : subclassSubgraphs ) {
final var subgraphType = subclassSubgraph.type();
final var graphJavaType = entityGraph.getGraphedType().getJavaType();
if ( !graphJavaType.isAssignableFrom( subgraphType ) ) {
throw new AnnotationException( "Named subgraph type '" + subgraphType.getName()
+ "' is not a subtype of the graph type '" + graphJavaType.getName() + "'" );
+ "' is not a subtype of the graph type '" + graphJavaType.getName() + "'" );
}
@SuppressWarnings("unchecked") // Safe, because we just checked
final Class<? extends T> subtype = (Class<? extends T>) subgraphType;
final GraphImplementor<? extends T> subgraph = entityGraph.addTreatedSubgraph( subtype );
applyNamedAttributeNodes( subclassSubgraph.attributeNodes(), annotation, subgraph );
applyNamedAttributeNodes( subclassSubgraph.attributeNodes(), annotation,
entityGraph.addTreatedSubgraph( subgraphType.asSubclass( graphJavaType ) ) );
}
}

Expand All @@ -72,7 +71,7 @@ private static <T> RootGraphImplementor<T> createRootGraph(
String name,
EntityDomainType<T> rootEntityType,
boolean includeAllAttributes) {
final RootGraphImpl<T> entityGraph = new RootGraphImpl<>( name, rootEntityType );
final var entityGraph = new RootGraphImpl<>( name, rootEntityType );
if ( includeAllAttributes ) {
for ( var attribute : rootEntityType.getAttributes() ) {
entityGraph.addAttributeNodes( attribute );
Expand All @@ -85,7 +84,7 @@ private void applyNamedAttributeNodes(
NamedAttributeNode[] namedAttributeNodes,
NamedEntityGraph namedEntityGraph,
GraphImplementor<?> graphNode) {
for ( NamedAttributeNode namedAttributeNode : namedAttributeNodes ) {
for ( var namedAttributeNode : namedAttributeNodes ) {
final var attributeNode =
(AttributeNodeImplementor<?,?,?>)
graphNode.addAttributeNode( namedAttributeNode.value() );
Expand All @@ -105,7 +104,7 @@ private <T,E,K> void applyNamedSubgraphs(
String subgraphName,
AttributeNodeImplementor<T,E,K> attributeNode,
boolean isKeySubGraph) {
for ( NamedSubgraph namedSubgraph : namedEntityGraph.subgraphs() ) {
for ( var namedSubgraph : namedEntityGraph.subgraphs() ) {
if ( subgraphName.equals( namedSubgraph.name() ) ) {
applyNamedAttributeNodes( namedSubgraph.attributeNodes(), namedEntityGraph,
createSubgraph( attributeNode, isKeySubGraph, namedSubgraph.type() ) );
Expand All @@ -128,27 +127,27 @@ private static SubGraphImplementor<?> createSubgraph(

private static <T, E, K> SubGraphImplementor<?> makeAttributeNodeValueSubgraph(
AttributeNodeImplementor<T, E, K> attributeNode, Class<?> subgraphType) {
final Class<?> attributeValueType =
attributeNode.getAttributeDescriptor().getValueGraphType().getJavaType();
final var attributeValueType =
attributeNode.getAttributeDescriptor()
.getValueGraphType().getJavaType();
if ( !attributeValueType.isAssignableFrom( subgraphType ) ) {
throw new AnnotationException( "Named subgraph type '" + subgraphType.getName()
+ "' is not a subtype of the value type '" + attributeValueType.getName() + "'" );
+ "' is not a subtype of the value type '" + attributeValueType.getName() + "'" );
}
@SuppressWarnings("unchecked") // Safe, because we just checked
final Class<? extends E> castType = (Class<? extends E>) subgraphType;
return attributeNode.addValueSubgraph().addTreatedSubgraph( castType );
return attributeNode.addValueSubgraph().addTreatedSubgraph(
subgraphType.asSubclass( attributeNode.getValueSubgraph().getClassType() ) );
}

private static <T, E, K> SubGraphImplementor<?> makeAttributeNodeKeySubgraph(
AttributeNodeImplementor<T, E, K> attributeNode, Class<?> subgraphType) {
final Class<?> attributeKeyType =
attributeNode.getAttributeDescriptor().getKeyGraphType().getJavaType();
final var attributeKeyType =
attributeNode.getAttributeDescriptor()
.getKeyGraphType().getJavaType();
if ( !attributeKeyType.isAssignableFrom( subgraphType ) ) {
throw new AnnotationException( "Named subgraph type '" + subgraphType.getName()
+ "' is not a subtype of the key type '" + attributeKeyType.getName() + "'" );
+ "' is not a subtype of the key type '" + attributeKeyType.getName() + "'" );
}
@SuppressWarnings("unchecked") // Safe, because we just checked
final Class<? extends K> castType = (Class<? extends K>) subgraphType;
return attributeNode.addKeySubgraph().addTreatedSubgraph( castType );
return attributeNode.addKeySubgraph().addTreatedSubgraph(
subgraphType.asSubclass( attributeNode.getKeySubgraph().getClassType() ) );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ public GlobalRegistrationsImpl(ModelsContext sourceModelContext, BootstrapContex

@Override
public <T> T as(Class<T> type) {
//noinspection unchecked
return (T) this;
return type.cast( this );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ public void injectInterceptor(
PersistentAttributeInterceptor interceptor,
SharedSessionContractImplementor session) {
if ( !enhancedForLazyLoading ) {
throw new NotInstrumentedException( "Entity class [" + entityClass.getName() + "] is not enhanced for lazy loading" );
throw new NotInstrumentedException( "Entity class '" + entityClass.getName()
+ "' is not enhanced for lazy loading" );
}

if ( !entityClass.isInstance( entity ) ) {
Expand All @@ -291,7 +292,8 @@ public void injectInterceptor(
@Override
public @Nullable BytecodeLazyAttributeInterceptor extractLazyInterceptor(Object entity) throws NotInstrumentedException {
if ( !enhancedForLazyLoading ) {
throw new NotInstrumentedException( "Entity class [" + entityClass.getName() + "] is not enhanced for lazy loading" );
throw new NotInstrumentedException( "Entity class [" + entityClass.getName()
+ "] is not enhanced for lazy loading" );
}

if ( !entityClass.isInstance( entity ) ) {
Expand Down
Loading
Loading