Java MCQ: Which annotation is used to mark a class as an entity in JPA?
a) @Table
b) @Column
c) @Entity
d) @Persistence
Answer:
c) @Entity
Explanation:
The @Entity
annotation is used to mark a class as an entity in JPA. An entity represents a table in the database, and each instance of the entity class corresponds to a row in the table. The @Entity
annotation tells the JPA provider to manage this class as a persistent entity.
Here’s an example of an entity class:
@Entity
public class Employee {
@Id
private Long id;
private String name;
// Getters and setters
}
In this example, the Employee
class is marked as an entity using the @Entity
annotation, and it will be mapped to a table in the database.
Entities are central to JPA as they represent the data that is persisted and managed by the application.
Reference links:
https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html