Ticket 1.5: Verify DirectCopyClassTransformer compatibility with Hibernate 6#6
Open
devin-ai-integration[bot] wants to merge 4 commits intodevelop-7.0.xfrom
Open
Conversation
- Add Hibernate 6 compatibility documentation to DirectCopyClassTransformer explaining transformation ordering guarantees (weaving before metamodel) - Update getNewCacheAnnotation() to support JPA-standard jakarta.persistence.Cache annotations in addition to Hibernate-specific @Cache (deprecated in Hibernate 6.2+) - Add defensive error handling in BroadleafHibernateEnhancingClassTransformerImpl to gracefully handle Javassist-transformed bytecode that Hibernate 6 enhancer cannot fully process - Add Hibernate 6 compatibility Javadoc to BroadleafCommonConfig explaining transformer ordering and internal API usage - Add Hibernate 6 compatibility note to ConditionalDirectCopyTransformersManager confirming it operates at Spring config level with no Hibernate dependency - Create DirectCopyTransformHibernate6CompatibilityValidator for startup validation that woven fields are visible to Hibernate's JPA metamodel - Register validator bean in bl-common-applicationContext.xml (lazy-init) Co-Authored-By: Arjun Mishra <arjunsaxmishra@gmail.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
- Change enhancement exception logging from DEBUG to WARN level in BroadleafHibernateEnhancingClassTransformerImpl so operators are alerted when bytecode enhancement is skipped for a class - Remove dead code branch in getNewCacheAnnotation() that incorrectly handled jakarta.persistence.Cache (which is a JPA interface, not an annotation) with wrong enum type mapping (CacheStoreMode) - Update Javadoc to correctly note that @Cacheable migration would require changes to both buildClassCacheAnnotation and getNewCacheAnnotation Co-Authored-By: Arjun Mishra <arjunsaxmishra@gmail.com>
…h only RuntimeException - Re-throw IllegalClassFormatException so genuine class format problems propagate to the caller and can abort class loading - Only catch RuntimeException (e.g., ASM/Javassist bytecode incompatibilities) to prevent application crash while allowing the class to load unenhanced - Include full stack trace in WARN log for root-cause analysis - Add explicit warning in log message about impact on lazy loading and dirty checking when enhancement is skipped Co-Authored-By: Arjun Mishra <arjunsaxmishra@gmail.com>
…artup The DirectCopyTransformHibernate6CompatibilityValidator was configured with lazy-init=true, but nothing references it, so its @PostConstruct validation would never execute. Changed to lazy-init=false so it eagerly initializes and validates woven field visibility in the JPA metamodel at startup. Co-Authored-By: Arjun Mishra <arjunsaxmishra@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Brief Overview
Investigation of whether the Javassist-based
DirectCopyClassTransformerload-time weaving infrastructure is compatible with Hibernate 6's refactored metamodel scanner and bytecode enhancement. The codebase currently uses Hibernate 5.6.15.Final; these changes prepare and document the weaving pipeline for a future Hibernate 6 migration.Labels: Enhancement, Status: ready-for-code-review
Changes
Documentation (majority of diff): Added Hibernate 6 compatibility Javadoc to
DirectCopyClassTransformer,BroadleafHibernateEnhancingClassTransformerImpl,BroadleafCommonConfig, andConditionalDirectCopyTransformersManagerexplaining transformation ordering guarantees and known integration points with Hibernate internals.getNewCacheAnnotation()— Hibernate 6 Javadoc: Added documentation noting that@org.hibernate.annotations.Cacheis deprecated in Hibernate 6.2+ in favor of@jakarta.persistence.Cacheable, but is still fully processed by Hibernate 6. No behavioral change to the method — the Javadoc documents what would need to change if templates migrate to@Cacheablein the future.BroadleafHibernateEnhancingClassTransformerImpl— narrowed defensive try/catch: Wrapssuper.transform()with targeted exception handling:IllegalClassFormatException(checked) is re-thrown so genuine class format problems still abort class loading, whileRuntimeException(e.g., ASM/Javassist bytecode incompatibilities) is caught, logged at WARN with full stack trace, and skipped to prevent application crash.DirectCopyTransformHibernate6CompatibilityValidator(new): A Spring bean (lazy-init="false") that eagerly validates at startup that woven attributes (e.g.archiveStatus) are visible in Hibernate's JPA metamodel. Registered inbl-common-applicationContext.xml.RuntimeException swallowing in enhancer — the new
catch (RuntimeException e)returnsnulland logs at WARN with full stack trace.IllegalClassFormatExceptionis properly re-thrown. This is still a behavioral change from the original code where all exceptions would propagate. Reviewers should confirm this fail-open behavior for runtime exceptions is acceptable.Validator persistence unit name — the validator uses
@PersistenceContext(unitName = "blPU"). Since the bean is now eagerly initialized (lazy-init="false"), a mismatched persistence unit name would cause a startup failure rather than a silent no-op. Confirm"blPU"matches the actual persistence unit name used in deployments.Validator checks only
archiveStatus— theCOMMON_WOVEN_ATTRIBUTESarray contains only one attribute. This provides a basic smoke test but won't catch issues with other woven fields likesandBoxDiscriminatorormultiTenantDiscriminator. Consider whether additional attributes should be checked.No runtime verification possible yet — the codebase is still on Hibernate 5.6.15.Final, so all compatibility analysis is theoretical. These changes cannot be validated against an actual Hibernate 6 runtime until the version is bumped.
Human Review Checklist
RuntimeExceptionwhile re-throwingIllegalClassFormatExceptionis the right boundary for fail-open behavior@PersistenceContext(unitName = "blPU")matches the actual persistence unit name used in deploymentsCOMMON_WOVEN_ATTRIBUTESshould include additional woven field names beyondarchiveStatusAdditional Context
ProductImpl,CategoryImpl,SkuImpl,CustomerImpl,OrderImpl,AdminUserImpl,PageImpl,StructuredContentImpl— all carry@DirectCopyTransformannotations and will receive woven fields.MergePersistenceUnitManagerforce-loads all managed classes beforeEntityManagerFactorycreation, guaranteeing Javassist weaving completes before Hibernate's metamodel build. This ordering holds for both Hibernate 5.x and 6.x.ConditionalDirectCopyTransformersManageroperates purely at the Spring configuration level with no Hibernate API dependency — confirmed compatible without changes.Link to Devin session: https://app.devin.ai/sessions/bd15110a14d449b5b66f5ab802995018
Requested by: @Colhodm