Skip to content

Refactor: Replace @ManyToMany with intermediary entity and improve Entity stability #709

@gratisreise

Description

@gratisreise
  1. Key Changes
  • Introduction of Intermediary Entity: Replaced @manytomany with a formal ProductTag entity, refactoring the relationship into @onetomany and @manytoone associations.
  • Enhanced Entity Stability: Removed the risky @DaTa annotation in favor of @Getter and @NoArgsConstructor(access = AccessLevel.PROTECTED) to ensure encapsulation and identifier integrity.
  • Explicit ID Generation: Replaced ambiguous @GeneratedValue with GenerationType.IDENTITY for better database predictability.
  • Optimized Fetching: Updated the NamedEntityGraph with Subgraphs to ensure Product, ProductTag, and Tag can still be fetched in a single optimized query.
  1. Expected Benefits
  • Extensibility: Allows for adding relationship-specific metadata (e.g., created_at, display_order) to the ProductTag entity without schema overhauls.
  • Runtime Reliability: Eliminates potential StackOverflowError during serialization and prevents HashSet inconsistency caused by mutable hashCode values in entities.
  • Query Control: Provides explicit control over the intermediary table, preventing performance degradation (such as the "Hibernate Bag" issue) during bulk data operations.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions