0
0
Spring Bootframework~10 mins

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

Spring Boot
public class User {
    @[1]
    private Profile profile;
}
Drag options to blanks, or click blank then click option'
AOneToOne
BManyToMany
COneToMany
DManyToOne
Attempts:
3 left
💡 Hint
Common Mistakes
Using @OneToMany or @ManyToOne which define different relationships.
Forgetting the '@' symbol before the annotation.
2fill in blank
medium

Complete the code to specify the owning side of a one-to-one relationship with a join column.

Spring Boot
public class User {
    @OneToOne
    @[1](name = "profile_id")
    private Profile profile;
}
Drag options to blanks, or click blank then click option'
AMappedBy
BJoinTable
CColumn
DJoinColumn
Attempts:
3 left
💡 Hint
Common Mistakes
Using @JoinTable instead of @JoinColumn for one-to-one relationships.
Confusing @Column with @JoinColumn.
3fill in blank
hard

Fix the error in the mappedBy attribute to correctly define the inverse side of the one-to-one relationship.

Spring Boot
public class Profile {
    @OneToOne(mappedBy = "[1]")
    private User user;
}
Drag options to blanks, or click blank then click option'
AprofileId
Buser
Cprofile
DuserId
Attempts:
3 left
💡 Hint
Common Mistakes
Using the class name instead of the field name in mappedBy.
Using the wrong field name that does not exist in the owning entity.
4fill in blank
hard

Fill both blanks to complete the bidirectional one-to-one relationship between User and Profile.

Spring Boot
public class User {
    @OneToOne
    @[1](name = "profile_id")
    private Profile profile;
}

public class Profile {
    @OneToOne(mappedBy = "[2]")
    private User user;
}
Drag options to blanks, or click blank then click option'
AJoinColumn
BJoinTable
Cprofile
Duser
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up JoinColumn and JoinTable annotations.
Using the wrong field name in mappedBy.
5fill in blank
hard

Fill all three blanks to create a one-to-one relationship with cascade and fetch type settings.

Spring Boot
public class User {
    @OneToOne(cascade = CascadeType.[1], fetch = FetchType.[2])
    @JoinColumn(name = "profile_id")
    private Profile [3];
}
Drag options to blanks, or click blank then click option'
AALL
BEAGER
Cprofile
DLAZY
Attempts:
3 left
💡 Hint
Common Mistakes
Using LAZY fetch when eager loading is intended.
Using incorrect cascade types like PERSIST only.
Naming the field something other than 'profile'.