Problem in loading collection using loader query after migrating from hibernate4 to hibernate5

Hi
I’ve have been migrating from hibernate 4.3.11 to 5.3.29 and i’m facing issues in loading collection by using loader query and load-collection tag which looks like this

<sql-query name="loadCollection">
	<load-collection alias="nestedValuePersist" role="SomeEntity.memberNotEntity.nestedValuePersist"/>
		SELECT * FROM {h-schema}SOME_TABLE
		WHERE IN_SOME = 1
		AND ID_SOME = ?
</sql-query>

<component name="memberNotEntity" class="org.somepackage.SomeClassNotEntity">
	<property name="original" column="ID_SOME" type="string" />
	<property name="originalQualifier" column="1234_SOME" type="string" />
	<set name="nestedValuePersist" table="SOME_TABLE" collection-type="org.hibernate.usertype.UserCollectionType">
		<key column="ID_SOME" not-null="true" />
		<composite-element class="org.somepackage.SomeClassValue">
			<property name="value" column="TT_DOCVAL" type="string" not-null="true" />
		</composite-element>
        <loader query-ref="loadCollection"/> 
        (...)
	</set>
</component>
		

And it fails right here in ResultSetMappingBinder class
context.findEntityBinding((String)null, rtnSource.getRole().substring(0, dot))

    public static NativeSQLQueryReturn extractReturnDescription(JaxbHbmNativeQueryCollectionLoadReturnType rtnSource, HbmLocalMetadataBuildingContext context, int queryReturnPosition) {
        int dot = rtnSource.getRole().lastIndexOf(46);
        if (dot == -1) {
            throw new MappingException(String.format(Locale.ENGLISH, "Collection attribute for sql query return [%s] not formatted correctly {OwnerClassName.propertyName}", rtnSource.getAlias()), context.getOrigin());
        } else {
            String ownerClassName = context.findEntityBinding((String)null, rtnSource.getRole().substring(0, dot)).getClassName();
            String ownerPropertyName = rtnSource.getRole().substring(dot + 1);
            return new NativeSQLQueryCollectionReturn(rtnSource.getAlias(), ownerClassName, ownerPropertyName, extractPropertyResults(rtnSource.getAlias(), (NativeQueryNonScalarRootReturn)rtnSource, (PersistentClass)null, context), rtnSource.getLockMode());
        }
    }

As it tires to find entity for SomeEntity.memberNotEntity which is not an entity and results in NullPointerException
It used to work fine in previous version as ResultSetMappingBinder logic looked like this:

    private static NativeSQLQueryCollectionReturn bindLoadCollection(Element returnElem, Mappings mappings) {
        String alias = returnElem.attributeValue("alias");
        String collectionAttribute = returnElem.attributeValue("role");
        LockMode lockMode = getLockMode(returnElem.attributeValue("lock-mode"));
        int dot = collectionAttribute.lastIndexOf(46);
        if (dot == -1) {
            throw new MappingException("Collection attribute for sql query return [alias=" + alias + "] not formatted correctly {OwnerClassName.propertyName}");
        } else {
            String ownerClassName = HbmBinder.getClassName(collectionAttribute.substring(0, dot), mappings);
            String ownerPropertyName = collectionAttribute.substring(dot + 1);
            Map propertyResults = bindPropertyResults(alias, returnElem, (PersistentClass)null, mappings);
            return new NativeSQLQueryCollectionReturn(alias, ownerClassName, ownerPropertyName, propertyResults, lockMode);
        }
    }

The way of obtaining ownerClassName changed from
String ownerClassName = HbmBinder.getClassName(collectionAttribute.substring(0, dot), mappings)
to
String ownerClassName = context.findEntityBinding((String)null, rtnSource.getRole().substring(0, dot)).getClassName();

I was trying to flex my way through it by using setter that resides within entity but sets values for SomeEntity.memberNotEntity.nestedValuePersist, but then I receive

org.hibernate.MappingException: Could not locate CollectionPersister for role : SomeEntity.nestedValuePersist

I’m inexperienced in the depths of hibernate and I don’t really know where to go from here, so i would appreciate any help from you guys.

Hey there. See 5.3 series - Hibernate ORM and Maintenance Policy - Hibernate for details about our maintenance policy. If you’re a Red Hat customer, please open a support ticket and then we can look into this. Otherwise you will have to update to Hibernate ORM 6.4 to receive any support for bugs, though I doubt this is still a bug in ORM 6.

This will be fixed as part of [HHH-17532] - Hibernate JIRA. Thanks for creating the customer support case.