hibernate/hibernate-orm · error · PropertyAccessBuildingException

Could not locate field for property named [" + containerJava

Error message

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

What it means

PropertyAccessEnhancedImpl builds access for bytecode-enhanced entities: it resolves the access type (explicit class-level or inferred) and, for FIELD access, looks up the Field reflectively via fieldOrNull. A null result throws PropertyAccessBuildingException 'Could not locate field for property named [Class#property]' — the mapping references a property name that has no backing field on the class.

Source

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

	private final Setter setter;

	public PropertyAccessEnhancedImpl(
			PropertyAccessStrategy strategy,
			Class<?> containerJavaType,
			String propertyName,
			@Nullable AccessType classAccessType) {
		this.strategy = strategy;

		final var propertyAccessType =
				classAccessType == null
						? 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;
			}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Fix the mapped property name so it matches a declared field on containerJavaType exactly
  2. If the value lives on a getter, annotate that member with @Access(AccessType.PROPERTY) so PROPERTY access is resolved
  3. Re-run the bytecode-enhancement build task after renames so enhanced classes and mapping metadata agree
  4. Add a bootstrap test that builds the SessionFactory so bad property names fail at build time, not at runtime

Example fix

// before
@Access(AccessType.FIELD)
public class Order {
    @Column(name = "order_date")
    private LocalDate orderDat; // mapping/metadata says orderDate
}

// after
public class Order {
    @Column(name = "order_date")
    private LocalDate orderDate;
}
Defensive patterns

Strategy: validation

Validate before calling

// Fail fast at startup: every mapped property must exist as a field
for (String prop : new String[]{"orderDate", "amount", "status"}) {
    try {
        Order.class.getDeclaredField(prop);
    } catch (NoSuchFieldException e) {
        throw new IllegalStateException("Mapping references missing field: Order#" + prop, e);
    }
}

Try / catch

try {
    SessionFactory sf = metadata.buildSessionFactory();
} catch (org.hibernate.property.access.internal.PropertyAccessBuildingException e) {
    // mapping names a property with no backing field: fix the mapping or add @Access(PROPERTY)
}

Prevention

When it happens

Trigger: A mapping (XML <property name="..."> or annotation metadata) naming a property that is not a declared field, while the resolved access type is FIELD — typos, stale mapping files after a field rename, or metadata written for a different class version.

Common situations: Renaming a Java field without updating orm.xml or annotation metadata; @Access(AccessType.FIELD) on a class where the value only exists as a getter; Kotlin/Scala classes where the mapped name differs from the backing field; stale bytecode-enhanced classes after a refactor.

Related errors


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