Please add first-class support for JPA value objects using @Embeddable and @Embedded in JHipster Domain Language (JDL).
Today, JDL supports entities/DTOs/relationships and can generate common JPA mappings, but it lacks a dedicated way to model embeddable components and to embed them inside entities (e.g., address-like value objects, geo coordinates, monetary values, audit value groups, etc.). Users who want to model rich domain concepts as value types must currently rely on workarounds such as:
generating code manually and then maintaining it outside JDL, using custom mapping snippets (if available in their workflow), or flattening the model into entity fields (losing structure and reusability). The requested enhancement would allow users to define embeddable types in JDL and reference them from entities, with correct generation of:
the @Embeddable class the owning entity property annotated with @Embedded appropriate fields, column mapping, and naming conventions validation annotations (if JDL constraints are provided for embeddable fields) equality/hashCode behavior (if JHipster typically generates them for other value-style types) import cleanup and compilation correctness across the generated codebase
Motivation for or Use Case
In many real-world domains, data naturally forms value objects that should be reused across multiple entities and treated as a single conceptual unit.
Common use cases:
Address / Contact info reuse
Multiple entities share the same address structure (e.g., BillingAddress, ShippingAddress, UserAddress), and each should map to columns via a single embeddable type. Financial/money modeling
Money often includes amount + currency. Embedding prevents repeating the same fields across entities and reduces modeling errors. Geolocation / coordinates
Coordinates { lat, lng } is frequently embedded in multiple domain entities. Audit group or immutable value types
While JHipster already supports audit via Instant/User patterns, some projects require value-based audit components or custom “audit metadata” groups. Domain-driven design consistency
JPA @Embeddable / @Embedded is a direct and standard mechanism to express value objects in the persistence layer. Supporting it in JDL lets users keep their model as a value-oriented domain model while still relying on JHipster for code generation. Adding this feature to JDL improves maintainability and reduces technical debt by allowing embeddables to be defined once and reused across entities—without manual edits that may be overwritten when re-generating.
Proposed JDL syntax (example) Below is a possible JDL shape (not claiming final syntax; just illustrating the desired capability).
entity Customer {
name String
primaryAddress PrimaryAddress
}
entity Supplier {
name String
headquartersAddress PrimaryAddress
}
embeddable PrimaryAddress {
street String
city String
zipCode String
country String
}
And optionally (if JDL needs explicit @Embedded naming):
entity Customer {
name String
homeAddress PrimaryAddress required
}
The generator would then produce:
PrimaryAddress as @Embeddable Customer.homeAddress as @Embedded column mapping with a consistent prefix (e.g., home_address_street or home_address_city) aligned with JHipster’s conventions and/or configurable naming strategy. Acceptance criteria / expected behavior JDL supports embeddable definitions
JDL can declare an embeddable type (e.g., embeddable X { ... }). Entities can embed embeddables
Entities can include embeddable properties. Correct JPA annotations are generated
Embeddable type is annotated with @Embeddable Embedded properties are annotated with @Embedded Column mapping is generated consistently
Each embeddable field maps to a column Naming strategy must avoid collisions when multiple embeddables are embedded in the same entity Validation constraints are supported
If JDL includes validation constraints for embeddable fields, they should be generated on the embeddable fields (or appropriately on the entity level). DTO generation remains coherent
Embedded fields are represented in DTOs (flattened or nested depending on JHipster conventions—either is acceptable as long as it’s consistent and documented). Re-generation is safe
The generated code compiles and can be re-generated without breaking user edits (i.e., embeddables are fully modeled in JDL rather than via manual hacks).
- Checking this box is mandatory (this is just to show you read everything)
Source: jhipster/generator-jhipster