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

**URL:** <https://discourse.hibernate.org/t/problem-in-loading-collection-using-loader-query-after-migrating-from-hibernate4-to-hibernate5/8630>\
**Category:** Hibernate ORM\
**Created:** [November 29, 2023, 5:34pm UTC](https://discourse.hibernate.org/t/problem-in-loading-collection-using-loader-query-after-migrating-from-hibernate4-to-hibernate5/8630 "2023-11-29T17:34:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wojtekson21](https://avatars.discourse-cdn.com/v4/letter/w/49beb7/32.png) [@wojtekson21](https://discourse.hibernate.org/u/wojtekson21)\
**Post date:** [November 29, 2023, 5:34pm UTC](https://discourse.hibernate.org/t/problem-in-loading-collection-using-loader-query-after-migrating-from-hibernate4-to-hibernate5/8630/1 "2023-11-29T17:34:57Z")

</div>

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

```auto
<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))`

```auto
    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:

```auto
    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

```auto
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.

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [November 30, 2023, 2:23pm UTC](https://discourse.hibernate.org/t/problem-in-loading-collection-using-loader-query-after-migrating-from-hibernate4-to-hibernate5/8630/2 "2023-11-30T14:23:32Z")

</div>

Hey there. See [5.3 series - Hibernate ORM](https://hibernate.org/orm/releases/5.3/) and [Maintenance Policy - Hibernate](https://hibernate.org/community/maintenance-policy/) 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.

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [December 8, 2023, 12:22pm UTC](https://discourse.hibernate.org/t/problem-in-loading-collection-using-loader-query-after-migrating-from-hibernate4-to-hibernate5/8630/3 "2023-12-08T12:22:13Z")

</div>

This will be fixed as part of [[HHH-17532] - Hibernate JIRA](https://hibernate.atlassian.net/browse/HHH-17532). Thanks for creating the customer support case.
