Problems with generics attributes

Jira Issue 18218 - Dynamic instantiation with generic entity attribute fails constructor argument type validation was dealing with case when generic attribute inherited from superclass, used as constructor argument. However, this is just a “tip of an iceberg”, every operation that references such attribute will cause similar (but distinct) problems. It is important to mention that constructor is not problem per se, only a way how the problem is made visible.

Some of operations I’ve tested are binary expression, unary expression, and function. It is very unlikely that this is final list. Each of mentioned problems should be handled
on different part of the code to be fixed. In my opinion this is bad approach. Attributes inherited as generics should be treated as “normal” arguments with concrete class in subclass whenever possible.

Suggested fix of the problem is to revert all three code fix commits used in HH-18218 -

0534e1aa01bd0a73837613d8f59efb5ba1b6512f
4c8e72c5ecfa1901298b73cf47e30ff97463b01e
2772a9d6fb2ca5c5e0f582ec18bf2a892d7a69ad

and to change method

org.hibernate.metamodel.model.domain.AbstractManagedType.findAttribute(String) in a way that if findDeclaredAttribute returns null, next attempt is to check for concrete generic attribute by calling findConcreteGenericAttribute, before trying findAttributeInSuperTypes.

Such fix will make all tests from HH-18218, plus new ones with operations I’ve mentioned above, to pass.

However, some existing tests will now fail, namely:

org.hibernate.orm.test.annotations.embeddables.generics.GenericEmbeddedIdentifierMappedSuperclassTest
org.hibernate.orm.test.annotations.embeddables.generics.GenericEmbeddedPropertyMappedSuperclassTest
org.hibernate.orm.test.annotations.generics.EmbeddedIdGenericsSuperclassTest
org.hibernate.orm.test.annotations.generics.GenericBasicValuedPathTest
org.hibernate.orm.test.annotations.generics.GenericMapAssociationTest
org.hibernate.orm.test.annotations.generics.GenericMappedSuperclassAssociationTest
org.hibernate.orm.test.annotations.generics.GenericMappedSuperclassNestedJoinTest
org.hibernate.orm.test.annotations.generics.GenericToManyAssociationTest
org.hibernate.orm.test.annotations.generics.GenericToOneAssociationTest
org.hibernate.orm.test.annotations.generics.MultipleEmbeddedGenericsTest

Common to failed tests is that they are all checking if attribute type (in subclass) is upper bound of genereic from superclass. As I said before, this is incorrect, and attribute in subclass should be of type as defined in subclass.

When tests are changed to validate resolved type as one in subclass, all tests are passing.

Can not find reason why type of inherited generic attribute should be resolved in a current way, since none of Jira issues connected to failed tests

HHH-16188 Exception when find by field of generic @EmbeddedId with @MappedSuperclass
HHH-16238 Add support for multiple generic embeddable properties in MappedSuperclass
HHH-16378 SQM fails to resolve target type of association defined in mappersuperclass with generics
HHH-16491 SQM could not correct resolve Generics Embeddable ids
HHH-17405 Cannot resolve path of generic mapped-superclass association path
HHH-17606 Cannot resolve path of nested generic mapped-superclass joins

is requesting current behavior, all are about parsing problems.

Please see my comment on the new Jira issue you opened regarding this proposed change.