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:

Attachments

1

Activity

Show:

Andrea Boriero December 4, 2024 at 10:47 AM

Hi as commented on the PR hbm.xml is deprecated and we are not planning to add any further improvement so I’m going to close the Jira.

Michael Hill May 3, 2019 at 5:06 PM

I have a first pass (as a first-time contributor) PR that I'll be posting shortly.

Won't Fix

Details

Assignee

Reporter

Labels

Worked in

Original estimate

Time tracking

No time logged

Components

Affects versions

Priority

Created May 3, 2019 at 5:01 PM
Updated December 4, 2024 at 10:48 AM
Resolved December 4, 2024 at 10:48 AM