hibernate/hibernate-orm · error · PersistenceException

Property {} was set to '{}', which is not compatible with th

Error message

Property {} was set to '{}', which is not compatible with the expected type {}

What it means

Same contract as the provider-level check, thrown from EntityManagerFactoryBuilderImpl.getEnhancementContext during EntityManagerFactory build: the value under hibernate.enhancer.bytecodeprovider.instance must be an org.hibernate.bytecode.spi.BytecodeProvider instance. Any other non-null type (a name String like "bytebuddy", a Class, a map) fails with this PersistenceException before the enhancement context is created.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java:529

		final Object propertyValue = configurationValues.remove( propertyName );
		return propertyValue != null && parseBoolean( propertyValue.toString() );
	}

	/**
	 * Builds the context to be used in runtime bytecode enhancement
	 *
	 * @param dirtyTrackingEnabled To enable dirty tracking feature
	 * @param lazyInitializationEnabled To enable lazy initialization feature
	 * @param associationManagementEnabled To enable association management feature
	 * @return An enhancement context for classes managed by this EM
	 */
	protected EnhancementContext getEnhancementContext(
			final boolean dirtyTrackingEnabled,
			final boolean lazyInitializationEnabled,
			final boolean associationManagementEnabled ) {
		final Object propValue = configurationValues.get( BYTECODE_PROVIDER_INSTANCE );
		if ( propValue != null && ( ! ( propValue instanceof BytecodeProvider ) ) ) {
			throw new PersistenceException( "Property " + BYTECODE_PROVIDER_INSTANCE + " was set to '" + propValue
							+ "', which is not compatible with the expected type " + BytecodeProvider.class );
		}
		final var overriddenBytecodeProvider = (BytecodeProvider) propValue;
		return new DefaultEnhancementContext() {

			@Override
			public boolean isEntityClass(UnloadedClass classDescriptor) {
				return managedResources.getAnnotatedClassNames().contains( classDescriptor.getName() )
					&& super.isEntityClass( classDescriptor );
			}

			@Override
			public boolean isCompositeClass(UnloadedClass classDescriptor) {
				return managedResources.getAnnotatedClassNames().contains( classDescriptor.getName() )
					&& super.isCompositeClass( classDescriptor );
			}

			@Override

View on GitHub (pinned to fad1729dce)

Solutions

  1. Use the name-based setting hibernate.bytecode.provider = "bytebuddy" for selection by string
  2. Or put a real BytecodeProvider instance under hibernate.enhancer.bytecodeprovider.instance
  3. Drop the setting if the default provider suffices

Example fix

// before
configurationValues.put("hibernate.enhancer.bytecodeprovider.instance", "bytebuddy");

// after
configurationValues.put("hibernate.bytecode.provider", "bytebuddy"); // name-based
// or
// configurationValues.put("hibernate.enhancer.bytecodeprovider.instance", myBytecodeProvider);
Defensive patterns

Strategy: type-guard

Validate before calling

Object candidate = configurationValues.get("hibernate.enhancer.bytecodeprovider.instance");
if (candidate != null && !(candidate instanceof org.hibernate.bytecode.spi.BytecodeProvider)) {
    configurationValues.put("hibernate.bytecode.provider", String.valueOf(candidate));
    configurationValues.remove("hibernate.enhancer.bytecodeprovider.instance");
}

Type guard

static boolean isBytecodeProviderInstance(Object v) {
    return v == null || v instanceof org.hibernate.bytecode.spi.BytecodeProvider;
}

Prevention

When it happens

Trigger: configurationValues.put("hibernate.enhancer.bytecodeprovider.instance", "bytebuddy") or a class-name string in persistence.xml properties, hitting the boot builder path (e.g. via EntityManagerFactoryBuilder or native bootstrapping) rather than HibernatePersistenceProvider.

Common situations: Migrating name-based provider config to the instance setting without switching the value type; shared config maps reused across provider and builder bootstraps; YAML config that coerces objects to strings.

Related errors


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