Skip to main content
InterviewHubPRO
Section Overview
Q25

Question 25 of 50

Part 3: Microservices, Distributed Systems & Observability (25 - 35)

50%
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 @Embeddable class 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.