0
0
Spring Bootframework~10 mins

@OneToMany relationship 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 one-to-many relationship in a Spring Boot entity.

Spring Boot
import jakarta.persistence.*;

@Entity
public class Department {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String name;

    @[1]
    private List<Employee> employees;

    // getters and setters
}
Drag options to blanks, or click blank then click option'
AOneToOne
BOneToMany
CManyToOne
DManyToMany
Attempts:
3 left
💡 Hint
Common Mistakes
Using @ManyToOne instead of @OneToMany
Using @OneToOne which is for one-to-one relationships
2fill in blank
medium

Complete the code to specify the mappedBy attribute in the @OneToMany annotation.

Spring Boot
@OneToMany(mappedBy = "[1]")
private List<Order> orders;
Drag options to blanks, or click blank then click option'
Acustomer
Border
Corders
Dcustomers
Attempts:
3 left
💡 Hint
Common Mistakes
Using the plural form 'orders' instead of the singular 'customer'
Confusing the owning side field name
3fill in blank
hard

Fix the error in the @OneToMany annotation to enable cascade operations.

Spring Boot
@OneToMany(cascade = CascadeType.[1])
private Set<Item> items;
Drag options to blanks, or click blank then click option'
ADETACH
BPERSIST
CREFRESH
DALL
Attempts:
3 left
💡 Hint
Common Mistakes
Using only PERSIST or DETACH which limits cascade behavior
Forgetting to add cascade attribute
4fill in blank
hard

Fill both blanks to complete the bidirectional @OneToMany and @ManyToOne relationship.

Spring Boot
public class Parent {

    @OneToMany(mappedBy = "[1]", cascade = CascadeType.ALL)
    private List<Child> children;
}

public class Child {

    @[2]
    private Parent parent;
}
Drag options to blanks, or click blank then click option'
Aparent
BOneToMany
CManyToOne
Dchildren
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the annotations between Parent and Child
Using wrong field names in mappedBy
5fill in blank
hard

Fill all three blanks to complete the @OneToMany relationship with fetch type and orphan removal.

Spring Boot
@OneToMany(mappedBy = "[1]", fetch = FetchType.[2], orphanRemoval = [3])
private List<Comment> comments;
Drag options to blanks, or click blank then click option'
Apost
BLAZY
Ctrue
DEAGER
Attempts:
3 left
💡 Hint
Common Mistakes
Using EAGER fetch which loads all data immediately
Setting orphanRemoval to false or missing it