Skip to content

Ticket 1.5: Verify DirectCopyClassTransformer compatibility with Hibernate 6#6

Open
devin-ai-integration[bot] wants to merge 4 commits intodevelop-7.0.xfrom
devin/ticket-1.5-directcopy-hibernate6
Open

Ticket 1.5: Verify DirectCopyClassTransformer compatibility with Hibernate 6#6
devin-ai-integration[bot] wants to merge 4 commits intodevelop-7.0.xfrom
devin/ticket-1.5-directcopy-hibernate6

Conversation

@devin-ai-integration
Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot commented Apr 17, 2026

Brief Overview

Investigation of whether the Javassist-based DirectCopyClassTransformer load-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, and ConditionalDirectCopyTransformersManager explaining transformation ordering guarantees and known integration points with Hibernate internals.

getNewCacheAnnotation() — Hibernate 6 Javadoc: Added documentation noting that @org.hibernate.annotations.Cache is 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 @Cacheable in the future.

BroadleafHibernateEnhancingClassTransformerImpl — narrowed defensive try/catch: Wraps super.transform() with targeted exception handling: IllegalClassFormatException (checked) is re-thrown so genuine class format problems still abort class loading, while RuntimeException (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 in bl-common-applicationContext.xml.

⚠️ Items Requiring Careful Review

  1. RuntimeException swallowing in enhancer — the new catch (RuntimeException e) returns null and logs at WARN with full stack trace. IllegalClassFormatException is 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.

  2. 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.

  3. Validator checks only archiveStatus — the COMMON_WOVEN_ATTRIBUTES array contains only one attribute. This provides a basic smoke test but won't catch issues with other woven fields like sandBoxDiscriminator or multiTenantDiscriminator. Consider whether additional attributes should be checked.

  4. 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

  • Verify that catching RuntimeException while re-throwing IllegalClassFormatException is the right boundary for fail-open behavior
  • Confirm @PersistenceContext(unitName = "blPU") matches the actual persistence unit name used in deployments
  • Decide whether COMMON_WOVEN_ATTRIBUTES should include additional woven field names beyond archiveStatus

Additional Context

  • Entities verified: ProductImpl, CategoryImpl, SkuImpl, CustomerImpl, OrderImpl, AdminUserImpl, PageImpl, StructuredContentImpl — all carry @DirectCopyTransform annotations and will receive woven fields.
  • Key architectural finding: MergePersistenceUnitManager force-loads all managed classes before EntityManagerFactory creation, guaranteeing Javassist weaving completes before Hibernate's metamodel build. This ordering holds for both Hibernate 5.x and 6.x.
  • ConditionalDirectCopyTransformersManager operates purely at the Spring configuration level with no Hibernate API dependency — confirmed compatible without changes.
  • No DirectCopy infrastructure was removed or replaced per ticket constraints (that's Phase 3).

Link to Devin session: https://app.devin.ai/sessions/bd15110a14d449b5b66f5ab802995018
Requested by: @Colhodm


Open with Devin

- 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>
@devin-ai-integration
Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration Bot and others added 2 commits April 17, 2026 14:22
- 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>
devin-ai-integration[bot]

This comment was marked as resolved.

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant