Skip to content

feat(entity): add cascade option support for entity relationships#32659

Open
CharlesWong wants to merge 1 commit intojhipster:mainfrom
CharlesWong:feat/cascade-entity-relationships
Open

feat(entity): add cascade option support for entity relationships#32659
CharlesWong wants to merge 1 commit intojhipster:mainfrom
CharlesWong:feat/cascade-entity-relationships

Conversation

@CharlesWong
Copy link

Feature: Cascade Entity Relationships

Adds support for cascade operations on JHipster entity relationships, as requested in #12844.

JDL Syntax

relationship ManyToOne {
  Order{customer} to Customer with cascade
}

Generated Code

@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private Customer customer;

How It Works

The cascade keyword is added as a new relationship option token in the JDL grammar. When specified:

  1. The JDL lexer tokenizes cascade as a CASCADE token
  2. The parser accepts it in the relationshipOption rule alongside builtInEntity
  3. The AST builder visitor maps it to the cascade option name
  4. The JDL-to-JSON converter propagates it into relationship.options.cascade = true
  5. The relationship.options are spread onto the relationship object (existing behavior)
  6. The Jakarta Persistence EJS template emits the appropriate CascadeType on all relationship types

Supported Cascade Types

  • with cascadeCascadeType.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 — adds CASCADE constant
  • lib/jdl/core/parsing/lexer/lexer.ts — registers cascade token
  • lib/jdl/core/parsing/jdl-parser.ts — accepts cascade in relationshipOption rule
  • lib/jdl/core/parsing/jdl-ast-builder-visitor.ts — handles CASCADE token in visitor
  • lib/jdl/converters/jdl-to-json/jdl-to-json-relationship-converter.ts — propagates cascade option
  • generators/spring-boot/generators/data-relational/templates/.../_persistClass_.java.jhi.jakarta_persistence.ejs — emits CascadeType in JPA annotations

Closes #12844

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support to cascade all entities.

1 participant