Hibernate lets you map entities to a legacy schema without altering the database by using @Table and @Column annotations to explicitly bind Java class and field names to the existing table and column names, regardless of naming convention mismatches.
Key Points: • @Table(name = "...") overrides the default table name Hibernate would otherwise derive from the class name. • @Column(name = "...") maps a field to a specific, differently-named database column. • A custom PhysicalNamingStrategy can be registered to systematically translate Java naming conventions to legacy conventions across the whole application, avoiding per-field annotations. • @Id and @GeneratedValue can be adjusted to reflect legacy key generation approaches (e.g. sequence, identity, or a legacy trigger-based scheme). • This approach keeps the database schema completely untouched, which matters when other systems also depend on it.
Example: A legacy EMP_MASTER table with a column EMP_NM can be mapped to a clean Employee.name field just by annotating: @Table(name = "EMP_MASTER") on the class and @Column(name = "EMP_NM") on the field, with no schema changes required.
Code Example:
@Entity
@Table(name = "EMP_MASTER")
public class Employee {
@Id
@Column(name = "EMP_ID")
private Long id;
@Column(name = "EMP_NM")
private String name;
}Interview Tip: A concise interview answer is:
"I map legacy schemas by explicitly declaring @Table and @Column names on the entity to match whatever the existing database uses, or by registering a custom naming strategy if the mismatch is systematic across the whole schema — either way the database itself stays untouched."