MappedSuperClass with generic collections not mapped correctly

Description

We have noticed a critical issue with loading of entities with MapperSuperClasses having generic collections. The entities are not loaded correctly, where these generic collection fields are configured with other entities extending the same MapperSuperClass. Let me explain the situation with an example:

 

Let’s say we have a MappedSuperClass A with a generic collection field:

 

 

and subtypes:

 

 

The following jpql query throws an error:

 

Stacktrace:

 

So from the error it seems hibernate thinks ‘children' field belongs to the 'com.example.demo.entities.AItem' which doesn’t have this field.

 

Also I noticed that hibernate searches for a suitable type for the generic collection and it assigns it the first subtype it encounters such as AConfiguration instead of BConfiguration. If we had renamed Aconfiguration to CConfiguration then it doesn’t complain anymore.

 

This is a blocker for us and prevents us from using generic collections in the MappedSuperClasses.

Activity

Show:

Marco Belladelli May 29, 2023 at 9:57 AM

Hello , thank you for reporting the issue.

Your problem is very similar to , I will add your case to tests and continue working on a solution.

Note that since you’re querying BConfiguration explicitly you should be able to avoid the treat in your query, and Hibernate should resolve the items join to the correct type (BItem) but there seems to be another bug preventing that from working correctly so stay tuned for fixes.

Fixed

Details

Assignee

Reporter

Components

Sprint

Fix versions

Affects versions

Priority

Created May 25, 2023 at 9:55 AM
Updated June 15, 2023 at 9:23 AM
Resolved June 5, 2023 at 2:28 PM