Sobes.tech
Junior — Middle

Can you explain what the `@Table` annotation means in the context of ORM and what purposes it serves?

sobes.tech AI

Answer from AI

The @Table annotation in ORM (for example, in JPA) is used to specify which database table the entity class will be linked to. It allows setting the table name, schema, catalog, and unique constraints. If @Table is not specified, ORM typically uses the class name as the default table name.

Example of usage:

@Entity
@Table(name = "users", schema = "public")
public class User {
    @Id
    private Long id;
    private String name;
    // getters and setters
}

Here, the User class will be mapped to the users table in the public schema. This helps explicitly control the mapping between classes and database tables.

Can you explain what the `@Table` annotation means in… - sobes.tech