Default property access type not following JPA specification

Description

In 3.3.2, when an annotated entity has all annotations on getter methods, the property where accessed through the methods.

After updating to 5.2.10, the same entity class has being accessed directly through the fields.

Debugging I found that the implementation of the method org.hibernate.property.access.internal.PropertyAccessMixedImpl.getAccessType(Class<?>, String), has a logic that when there is no @Access annotation, defaults to AccessType.FIELD if a field with property name exists, otherwise defaults to AccessType.PROPERTY. And org.hibernate.property.access.internal.PropertyAccessEnhancedImpl inherits from it also.

JPA 2 specification introduced @Access, but kept compatibility for default behavior with JPA 1.0, as specified on section "2.3.1 Default Access Type":

When annotations are used to define a default access type, the placement of the mapping annotations on either the persistent fields or persistent properties of the entity class specifies the access type as being either field- or property-based access respectively.

So if I did not miss anything, I guess that org.hibernate.property.access.internal.PropertyAccessMixedImpl.getAccessType(Class<?>, String) should be adjusted to look where the other annotations are when calculating the default access type, instead of just looking if a field with property's name exists.

Environment

5.2.10.Final

Assignee

Luis Barreiro

Reporter

Rodrigo Faria

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Worked in

3.3.2

Components

Priority

Major
Configure