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

PropertyAccessGetterImpl builds getter-only access strategies (used where only reads are needed). It resolves the access type, and for FIELD access looks the Field up via fieldOrNull; a null result throws PropertyAccessBuildingException 'Could not locate field for property named [Class#property]' at mapping time — the property name has no backing field.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessGetterImpl.java:41

/**
 * A {@link PropertyAccess} based on mix of getter method or field.
 *
 * @author Gavin King
 */
public class PropertyAccessGetterImpl implements PropertyAccess {
	private final PropertyAccessStrategy strategy;

	private final Getter getter;

	public PropertyAccessGetterImpl(PropertyAccessStrategy strategy, Class<?> containerJavaType, String propertyName) {
		this.strategy = strategy;

		final var propertyAccessType = getAccessType( containerJavaType, propertyName );
		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 = fieldGetter( 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( containerJavaType, propertyName, getterMethod );
				break;
			}
			default: {
				throw new PropertyAccessBuildingException(

View on GitHub (pinned to fad1729dce)

Solutions

  1. Make the mapped property name match a declared field exactly
  2. If the value exists only as a getter, force PROPERTY access with @Access(AccessType.PROPERTY) on that member
  3. Re-run enhancement and rebuild metadata after field renames
  4. Bootstrap the SessionFactory in a test to surface mapping/property drift early

Example fix

// before
<attributes>
    <id name="identifer" .../> <!-- field is named identifier -->
</attributes>

// after
<attributes>
    <id name="identifier" .../>
</attributes>
Defensive patterns

Strategy: validation

Validate before calling

// Fail fast: every getter-only mapped property must have a backing field
try {
    OrderId.class.getDeclaredField("number");
} catch (NoSuchFieldException e) {
    throw new IllegalStateException("Mapping references missing field: OrderId#number", e);
}

Try / catch

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

Prevention

When it happens

Trigger: A getter-only strategy resolved for a mapped property whose name matches no declared field on containerJavaType — for example @EmbeddedId / virtual-id mappings after a field rename, an orm.xml typo, or computed getters where FIELD access was resolved from class-level @Access.

Common situations: Identifier and embedded-id mappings drifting from class changes; orm.xml property-name typos; refactors that renamed the field but left metadata behind; property names that only exist as getter methods with field access inferred.

Related errors


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