hibernate/hibernate-orm · error · HibernateException

Could not resolve PropertyAccess for attribute `%s#%s`

Error message

Could not resolve PropertyAccess for attribute `%s#%s`

What it means

Thrown while Hibernate builds the runtime metamodel for an embeddable (EmbeddableRepresentationStrategyPojo.buildPropertyAccess) when no PropertyAccessStrategy can be resolved for a mapped attribute. propertyAccessStrategy(...) asks the StrategySelector for a strategy able to access the property on the embeddable class; when it returns null - typically because the class has neither a field nor a getter matching the mapped attribute name - this HibernateException aborts SessionFactory creation and names the embeddable type and the offending attribute.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableRepresentationStrategyPojo.java:185

		}
		else {
			return new EmbeddableInstantiatorPojoStandard( embeddableClass, runtimeDescriptorAccess );
		}
	}

	private static ProxyFactoryFactory getProxyFactoryFactory(RuntimeModelCreationContext creationContext) {
		return creationContext.getServiceRegistry()
				.requireService( ProxyFactoryFactory.class );
	}

	private PropertyAccess buildPropertyAccess(
			Property property,
			Class<?> embeddableClass,
			boolean requireSetters,
			StrategySelector strategySelector) {
		final var strategy = propertyAccessStrategy( property, embeddableClass, strategySelector );
		if ( strategy == null ) {
			throw new HibernateException(
					String.format(
							Locale.ROOT,
							"Could not resolve PropertyAccess for attribute `%s#%s`",
							getEmbeddableJavaType().getTypeName(),
							property.getName()
					)
			);
		}
		return strategy.buildPropertyAccess( embeddableClass, property.getName(), requireSetters );
	}

	private static ReflectionOptimizer buildReflectionOptimizer(
			Component bootDescriptor,
			boolean hasCustomAccessors,
			PropertyAccess[] propertyAccesses,
			RuntimeModelCreationContext creationContext) {
		if ( !hasCustomAccessors
				&& bootDescriptor.getCustomInstantiator() == null

View on GitHub (pinned to fad1729dce)

Solutions

  1. Match the message's attribute name against the embeddable class members - add the missing field/getter or fix the name in the mapping
  2. If the field was renamed, update the XML/annotation accordingly (or use @AttributeOverride to align names)
  3. Clean and rebuild so the compiled embeddable class and the mapping metadata come from the same source version
  4. Ensure getters exist (or switch the mapping to field access) for the reported attribute

Example fix

// before
public class Address {
    private String streetName;   // mapping says 'street'
}
<component name="address">
    <property name="street" column="STREET"/>
</component>

// after - align the mapping with the field
<component name="address">
    <property name="streetName" column="STREET"/>
</component>
Defensive patterns

Strategy: validation

Validate before calling

// Verify every mapped attribute of the embeddable resolves to a field or getter
static void checkPropertyAccess(Class<?> embeddable, List<String> mappedAttributes) {
    for ( String attr : mappedAttributes ) {
        boolean hasField = Arrays.stream(embeddable.getDeclaredFields()).anyMatch(f -> f.getName().equals(attr));
        boolean hasGetter = false;
        try { embeddable.getMethod("get" + Character.toUpperCase(attr.charAt(0)) + attr.substring(1)); hasGetter = true; }
        catch (NoSuchMethodException ignored) {}
        if ( !hasField && !hasGetter ) throw new IllegalStateException("No member for attribute " + attr + " on " + embeddable);
    }
}

Type guard

static boolean attributeAccessible(Class<?> c, String attr) {
    try { c.getDeclaredField(attr); return true; } catch (NoSuchFieldException ignored) {}
    try { c.getMethod("get" + Character.toUpperCase(attr.charAt(0)) + attr.substring(1)); return true; } catch (NoSuchMethodException ignored) {}
    return false;
}

Try / catch

try {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("pu");
}
catch ( org.hibernate.HibernateException e ) {
    if ( e.getMessage() != null && e.getMessage().contains("Could not resolve PropertyAccess") ) {
        // message embeds `Type#attribute` - fix the mapping/class mismatch it names
        throw new ConfigurationError("Mapping/class mismatch: " + e.getMessage(), e);
    }
    throw e;
}

Prevention

When it happens

Trigger: XML <component> or <properties> mapping referencing a property name that does not exist on the embeddable class (renamed field, typo); annotation mappings where @AttributeOverrides/@AssociationOverride renames diverge from the actual Java member; embeddable class compiled without the field (stale jar on classpath) while the mapping metadata still lists it; access type mismatch where the expected getter is missing.

Common situations: Renaming embeddable fields without updating hbm.xml files; deployment mixing an old domain jar with new mapping files; copy-pasting @Embedded mappings between embeddable classes with different member names; Kotlin embeddables where the property is private with no public getter.

Related errors


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