Sobes.tech
Junior — Middle

What is the role of the @Embeddable annotation in ORM tools?

sobes.tech AI

Answer from AI

The @Embeddable annotation in ORM (such as in JPA/Hibernate) is used to denote a class that is not a standalone entity but is embedded within another entity as part of its state.

Role of @Embeddable:

  • Allows grouping related fields into a separate class for convenience and reuse.
  • Fields of a class with @Embeddable become columns in the parent entity's table.
  • Simplifies the data model structure by avoiding the creation of a separate table.

Example:

@Embeddable
public class Address {
    private String street;
    private String city;
    private String zipCode;
    // getters and setters
}

@Entity
public class User {
    @Id
    private Long id;

    @Embedded
    private Address address;
    // other fields
}

In this example, the Address fields will be stored in the User table as regular columns.

What is the role of the @Embeddable annotation in ORM… - sobes.tech