AceReady
JPA & Hibernate
Question 1 of 13
Easy

What are the basic annotations to map a JPA entity to a table ?

Answer

@Entity marks a class as a persistent entity, and @Table lets you specify the table name when it differs from the class name. @Id designates the field that acts as the primary key, often combined with @GeneratedValue to delegate identifier generation to the database or to a sequence. @Column then lets you customize a field's mapping, for example its column name, nullability or maximum length, when the default convention doesn't fit.

Common trap

A beginner trap is forgetting that a JPA entity needs a no-argument constructor, required by the persistence provider to instantiate the object through reflection before filling it with data read from the database.