{"record":{"id":"c1d18e4d458b6e64","repo":"hibernate/hibernate-orm","slug":"initialization-of-entity-enhancement-used-to-act-l","errorCode":null,"errorMessage":"Initialization of entity enhancement used to act like a proxy is not supported by this EntityPersister : {className}","messagePattern":"Initialization of entity enhancement used to act like a proxy is not supported by this EntityPersister : (.+?)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/persister/entity/EntityPersister.java","lineNumber":247,"sourceCode":"\n\tboolean isLazy();\n\n\tint getPropertySpan();\n\n\tboolean hasPreInsertGeneratedProperties();\n\n\tboolean hasPreUpdateGeneratedProperties();\n\n\t/**\n\t * Called from {@link EnhancementAsProxyLazinessInterceptor} to trigger load of\n\t * the entity's non-lazy state as well as the named attribute we are accessing\n\t * if it is still uninitialized after fetching non-lazy state.\n\t */\n\tdefault Object initializeEnhancedEntityUsedAsProxy(\n\t\t\tObject entity,\n\t\t\tString nameOfAttributeBeingAccessed,\n\t\t\tSharedSessionContractImplementor session) {\n\t\tthrow new UnsupportedOperationException(\n\t\t\t\t\"Initialization of entity enhancement used to act like a proxy is not supported by this EntityPersister : \"\n\t\t\t\t\t\t+ getClass().getName()\n\t\t);\n\t}\n\n\t/**\n\t * Determine whether the given name represents a subclass entity\n\t * (or this entity itself) of the entity mapped by this persister.\n\t *\n\t * @param entityName The entity name to be checked.\n\t * @return True if the given entity name represents either the entity\n\t * mapped by this persister or one of its subclass entities; false\n\t * otherwise.\n\t */\n\tboolean isSubclassEntityName(String entityName);\n\n\t/**\n\t * Returns an array of objects that identify spaces in which properties of","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/persister/entity/EntityPersister.java#L229-L265","documentation":"EntityPersister.initializeEnhancedEntityUsedAsProxy is invoked by EnhancementAsProxyLazinessInterceptor when a bytecode-enhanced entity acting as a lazy proxy has an attribute accessed and its non-lazy state must be loaded. The interface ships only a default implementation that throws UnsupportedOperationException; full persisters derived from AbstractEntityPersister override it, so any other EntityPersister implementation breaks on the first attribute access after load.","triggerScenarios":"Bytecode enhancement with lazy initialization enabled (gradle/maven plugin 'enableLazyInitialization'), loading an entity, then touching any attribute while its persister is not an AbstractEntityPersister subclass — e.g., a custom persister registered via @Persister or persisterClass.","commonSituations":"Custom EntityPersister implementations (auditing, tenancy, sharding) written before the enhanced-proxy feature; test doubles standing in as persisters; upgrading Hibernate where this default method was added to the interface.","solutions":["Drop the custom persisterClass/@Persister override so the standard persister is used","Override initializeEnhancedEntityUsedAsProxy in the custom persister (delegate to the persister's load path)","Reconfigure enhancement to dirty-tracking only (disable enableLazyInitialization) so enhanced instances are not used as proxies"],"exampleFix":"// before: custom persister without the override + enhancement lazy-init enabled\n@Entity @org.hibernate.annotations.Persister(impl = MyEntityPersister.class)\npublic class Customer { ... }\n\n// after: standard persister supports enhanced-proxy initialization\n@Entity\npublic class Customer { ... }","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static boolean supportsEnhancedProxyInitialization(EntityPersister persister) {\n    return persister instanceof org.hibernate.persister.entity.AbstractEntityPersister;\n}","tryCatchPattern":"try {\n    return entity.getName(); // first attribute access on an enhanced-as-proxy instance\n}\ncatch ( UnsupportedOperationException e ) {\n    // persister without initializeEnhancedEntityUsedAsProxy support\n    throw new IllegalStateException(\n        \"Bytecode-enhanced lazy loading is not supported by persister \"\n        + entity.getClass().getName(), e);\n}","preventionTips":["Do not combine custom EntityPersister implementations with enhancement lazy-initialization","When enabling 'enableLazyInitialization' in the enhance plugin, verify every entity uses a standard persister","Keep an upgrade test that loads and touches one attribute of every entity with enhancement enabled"],"tags":["hibernate","orm","bytecode-enhancement","lazy-loading","persister","proxy"],"backgroundTag":"unsupported-entity-persister-operation","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}