Relationships with no-op accessors fail during metamodel generation with NPEs

Description

Summary

When defining Hibernate one-to-many and many-to-many (bag/etc.) mappings using access="noop", session factory initialization fails. More specifically, JPA metamodel generation fails with NullPointerException while trying to process metadata related to access="noop" mappings.

When processing JPA entity metamodels for any-to-many associations, Hibernate expects mapping metadata to point to a non-null Member. However, the access="noop" handler (PropertyAccessStrategyNoopImpl.GetterImpl) always returns a null Member. Null {{Member}}s are not handled, leading to NPEs.

This is specifically an issue with entity metamodel generation and is not seen when disabling hibernate.ejb.metamodel.population.

Background

I know that access="noop" is a "secret" undocumented feature, but this feature has been very useful for our team. We are a small team maintaining a large application and have built a fair amount of dynamic query features around Hibernate. These queries depend on several relationships that are managed by the application but which don't exist as DTO fields. We are able to take advantage of these relationships by combining the lazy="true" and access="noop" attributes.

While this still technically works when using Hibernate criteria, it breaks when using the JPA metamodel. We recently upgraded from Hibernate 5.1.14 to Hibernate 5.4.2 and would like to begin our transition from Hibernate criteria to JPA.

Reproduction

Test case attached (to be added to hibernate-core/src/test/java/org/hibernate/test/propertyref).

Stack trace:

Environment

None

Status

Assignee

Michael Hill

Reporter

Michael Hill

Fix versions

None

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Worked in

5.1.14

Components

Affects versions

Priority

Major
Configure