0
0
Spring Bootframework~5 mins

JPA entity with @Entity annotation in Spring Boot - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the @Entity annotation do in a Spring Boot application?
The @Entity annotation marks a class as a JPA entity, meaning it represents a table in the database. It tells Spring Boot and JPA to manage this class for database operations.
Click to reveal answer
beginner
Which annotation is required to specify the primary key in a JPA entity?
The @Id annotation is used to mark a field as the primary key of the entity. This field uniquely identifies each record in the database table.
Click to reveal answer
intermediate
Why should a JPA entity class have a no-argument constructor?
JPA requires a no-argument constructor so it can create instances of the entity using reflection. This constructor can be public or protected.
Click to reveal answer
intermediate
What is the default table name for a JPA entity if @Table annotation is not used?
If @Table is not specified, the default table name is the same as the entity class name, usually case-sensitive depending on the database.
Click to reveal answer
beginner
How do you map a simple Java class to a database table using JPA?
You add the @Entity annotation to the class, mark a field with @Id for the primary key, and optionally use @Column to customize column mapping.
Click to reveal answer
What annotation marks a class as a JPA entity?
A@Entity
B@Table
C@Component
D@Repository
Which annotation identifies the primary key field in a JPA entity?
A@PrimaryKey
B@Id
C@Key
D@Column
What happens if a JPA entity class does not have a no-argument constructor?
AJPA will create the entity anyway
BCompilation error
CThe entity will be ignored
DRuntime error when JPA tries to instantiate the entity
If you don't specify @Table, what table name does JPA use?
AThe package name
BThe database default
CThe class name
DNo table is created
Which annotation customizes the column name in a JPA entity?
A@Column
B@Table
C@Entity
D@Id
Explain how to create a simple JPA entity class using @Entity and @Id annotations.
Think about how the class maps to a database table and how JPA identifies each record.
You got /4 concepts.
    Describe why the no-argument constructor is important in a JPA entity.
    Consider how JPA creates objects behind the scenes.
    You got /4 concepts.