0
0
Spring Bootframework~10 mins

JPA entity with @Entity annotation in Spring Boot - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a JPA entity class with the correct annotation.

Spring Boot
import jakarta.persistence.[1];

@[1]
public class User {
    private Long id;
    private String name;
}
Drag options to blanks, or click blank then click option'
AEntity
BTable
CColumn
DId
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Table instead of @Entity
Forgetting to import the annotation
Using @Id instead of @Entity
2fill in blank
medium

Complete the code to mark the primary key field with the correct annotation.

Spring Boot
import jakarta.persistence.Entity;
import jakarta.persistence.[1];

@Entity
public class Product {
    @[1]
    private Long id;
    private String name;
}
Drag options to blanks, or click blank then click option'
ATable
BColumn
CGeneratedValue
DId
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Column instead of @Id
Not annotating the primary key field
Using @Table on a field
3fill in blank
hard

Fix the error in the code by choosing the correct annotation to generate the primary key value automatically.

Spring Boot
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.[1];

@Entity
public class Order {
    @Id
    @[1]
    private Long id;
    private String product;
}
Drag options to blanks, or click blank then click option'
AColumn
BTable
CGeneratedValue
DEntity
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Column instead of @GeneratedValue
Forgetting to add @GeneratedValue for auto-generation
Using @Table on a field
4fill in blank
hard

Fill both blanks to complete the JPA entity with a primary key and a column annotation.

Spring Boot
import jakarta.persistence.Id;
import jakarta.persistence.[1];
import jakarta.persistence.[2];

@[1]
public class Customer {
    @Id
    private Long id;
    @[2](name = "customer_name")
    private String name;
}
Drag options to blanks, or click blank then click option'
AEntity
BTable
CColumn
DId
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Table instead of @Entity
Using @Id instead of @Column on the name field
Forgetting to import the annotations
5fill in blank
hard

Fill all three blanks to complete the JPA entity with @Entity, @Id, and @GeneratedValue annotations.

Spring Boot
import jakarta.persistence.[1];
import jakarta.persistence.[2];
import jakarta.persistence.[3];

@[1]
public class Invoice {
    @[2]
    @[3]
    private Long id;
    private Double amount;
}
Drag options to blanks, or click blank then click option'
AEntity
BId
CGeneratedValue
DColumn
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up @Column with @Id or @GeneratedValue
Forgetting to annotate the primary key
Not importing the correct annotations