Spring Boot & Microservices (50 Qs)•Part 3: Microservices, Distributed Systems & Observability (25 - 35)
What is the difference between Embedded IDs and IdClass in JPA?
senior LevelSystem DesignMicroservices
In Simple Words: Both represent composite primary keys in JPA:
@EmbeddedId: Defines a separate@Embeddableclass instance inside the entity (@EmbeddedId private OrderItemId id;). Clean and object-oriented.@IdClass: Annotates the entity with@IdClass(OrderItemId.class)and duplicates the primary key fields directly in the entity class.