hibernate/hibernate-orm · error · PropertyAccessBuildingException

Could not locate getter for property named [" + containerJav

Error message

Could not locate getter for property named [" + containerJavaType.getName() + "#" + propertyName + "]

What it means

The PROPERTY branch of PropertyAccessEnhancedImpl: after resolving access type PROPERTY, it looks up the getter via getterMethodOrNull(containerJavaType, propertyName). A null getter throws PropertyAccessBuildingException 'Could not locate getter for property named [Class#property]' — the mapping expects a JavaBean getter that does not exist on the class.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessEnhancedImpl.java:68

						? getAccessType( containerJavaType, propertyName )
						: classAccessType;

		switch ( propertyAccessType ) {
			case FIELD: {
				final var field = fieldOrNull( containerJavaType, propertyName );
				if ( field == null ) {
					throw new PropertyAccessBuildingException(
							"Could not locate field for property named [" + containerJavaType.getName() + "#" + propertyName + "]"
					);
				}
				getter = new GetterFieldImpl( containerJavaType, propertyName, field );
				setter = new EnhancedSetterImpl( containerJavaType, propertyName, field );
				break;
			}
			case PROPERTY: {
				final var getterMethod = getterMethodOrNull( containerJavaType, propertyName );
				if ( getterMethod == null ) {
					throw new PropertyAccessBuildingException(
							"Could not locate getter for property named [" + containerJavaType.getName() + "#" + propertyName + "]"
					);
				}
				getter = propertyGetter( classAccessType, containerJavaType, propertyName, getterMethod );
				setter = propertySetter( classAccessType, containerJavaType, propertyName, getterMethod.getReturnType() );
				break;
			}
			default: {
				throw new PropertyAccessBuildingException(
						"Invalid access type " + propertyAccessType + " for property named [" + containerJavaType.getName() + "#" + propertyName + "]"
				);
			}
		}
	}

	private static Getter propertyGetter(@Nullable AccessType classAccessType, Class<?> containerJavaType, String propertyName, Method getterMethod) {
		if ( classAccessType != null ) {
			final var explicitAccessType = getAccessType( containerJavaType, propertyName );

View on GitHub (pinned to fad1729dce)

Solutions

  1. Add the missing JavaBean getter (getOrderDate()) for the mapped property
  2. Or switch that member to FIELD access with @Access(AccessType.FIELD) if the value is field-backed
  3. Fix the property name in the mapping if it was a typo
  4. Keep a SessionFactory bootstrap test in CI to catch mapping/property drift at build time

Example fix

// before
@Entity @Access(AccessType.PROPERTY)
public class Order {
    private LocalDate orderDate; // no getter
}

// after
@Entity @Access(AccessType.PROPERTY)
public class Order {
    private LocalDate orderDate;
    public LocalDate getOrderDate() { return orderDate; }
}
Defensive patterns

Strategy: validation

Validate before calling

// Fail fast at startup: every property-mapped property needs a getter
try {
    Order.class.getDeclaredMethod("getOrderDate");
} catch (NoSuchMethodException e) {
    throw new IllegalStateException("Property access requires Order#getOrderDate()", e);
}

Try / catch

try {
    SessionFactory sf = metadata.buildSessionFactory();
} catch (org.hibernate.property.access.internal.PropertyAccessBuildingException e) {
    // expected getter missing: add it or switch the member to FIELD access
}

Prevention

When it happens

Trigger: Access type resolves to PROPERTY (class-level @Access(PROPERTY) or annotation-driven inference) but containerJavaType declares no getter for propertyName — for example <property name="orderDate"/> in orm.xml with only a field named orderDate and no getOrderDate().

Common situations: Renaming or deleting getters without updating XML mappings; Lombok annotation accidentally removed so the getter vanished; mappings written against an interface/DTO shape while applied to a class without the getter; field-only classes where access was globally set to property.

Related errors


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/903e6db350631420. Report an issue: GitHub.