feat(entity): add cascade option support for entity relationships#32659
Open
CharlesWong wants to merge 1 commit intojhipster:mainfrom
Open
feat(entity): add cascade option support for entity relationships#32659CharlesWong wants to merge 1 commit intojhipster:mainfrom
CharlesWong wants to merge 1 commit intojhipster:mainfrom
Conversation
…ipster#12844) Adds cascade support to JHipster entity relationships. When a relationship is defined with cascade, the generated JPA annotation includes the appropriate CascadeType values. JDL syntax: relationship ManyToOne { Order{customer} to Customer with cascade } Generates: @manytoone(fetch = FetchType.LAZY, cascade = CascadeType.ALL) private Customer customer; Changes: - Add CASCADE constant to relationship-options.ts - Add CASCADE token to JDL lexer - Add CASCADE to JDL parser's relationshipOption rule - Handle CASCADE in JDL AST builder visitor - Propagate cascade option through JDL-to-JSON converter - Update Jakarta Persistence EJS template to emit CascadeType on all relationship types (OneToMany, ManyToOne, ManyToMany, OneToOne) Supported cascade values: - 'cascade' (unary) — CascadeType.ALL - Future: specific cascade types (PERSIST, MERGE, REMOVE)
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.
Feature: Cascade Entity Relationships
Adds support for cascade operations on JHipster entity relationships, as requested in #12844.
JDL Syntax
Generated Code
How It Works
The
cascadekeyword is added as a new relationship option token in the JDL grammar. When specified:cascadeas aCASCADEtokenrelationshipOptionrule alongsidebuiltInEntitycascadeoption namerelationship.options.cascade = truerelationship.optionsare spread onto the relationship object (existing behavior)CascadeTypeon all relationship typesSupported Cascade Types
with cascade—CascadeType.ALL(unary shorthand)Supported Relationship Types
@OneToMany—@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, ...)@ManyToOne—@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)@ManyToMany—@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, ...)@OneToOne—@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, ...)Files Changed
lib/jdl/core/built-in-options/relationship-options.ts— addsCASCADEconstantlib/jdl/core/parsing/lexer/lexer.ts— registerscascadetokenlib/jdl/core/parsing/jdl-parser.ts— acceptscascadeinrelationshipOptionrulelib/jdl/core/parsing/jdl-ast-builder-visitor.ts— handlesCASCADEtoken in visitorlib/jdl/converters/jdl-to-json/jdl-to-json-relationship-converter.ts— propagates cascade optiongenerators/spring-boot/generators/data-relational/templates/.../_persistClass_.java.jhi.jakarta_persistence.ejs— emitsCascadeTypein JPA annotationsCloses #12844