Quiz 6 - 2
Quiz 6 - 2
Saved
All entities must use the @MappedSuperClass annotation since id, created, updated, and version fields can
only be placed in the mapped super class.
Question 1 options:
a) True
b) False
Question 2 (1 point)
Saved
What cascades are needed to only allow update and creation of new Student from BankAccount side? Select ALL
that apply. Please read: public enum CascadeType
Question 2 options:
a) Detach
b) Remove
c) Merge
d) Refresh
e) All
f) Persist
Question 3 (1 point)
Saved
What happens if cascade is not defined? Please read: @interface OneToMany
@OneToMany(mappedBy = "owningEmployee")
private List<Phone> phones;
Question 3 options:
Question 4 (1 point)
Saved
What does mappedBy mean? Please read: @interface OneToMany
@OneToMany(mappedBy = "owningEmployee", cascade = CascadeType.ALL, orphanRemoval = true)
Question 4 options:
d) Name of the column in the other table which owns the relationship.
Question 5 (1 point)
Saved
What is/are true about @MappedSuperclass annotation?
Question 5 options:
a) Class with @MappedSuperclass annotation has a separate table on the DB that it must map to.
b) The @MappedSuperclass annotation will lock the name of columns used, so it should only be used
when the desired tables for entities share the exact column names.
Question 6 (1 point)
Saved
Select all annotations which represent the relationship between two entities/tables in JPA.
Question 6 options:
a) @ManyToMany
b) @ManyToOne
c) @Inheritance
d) @ManyToOne
e) @JoinColumn
f) @OneToMany
Question 7 (1 point)
Saved
Assume everything else is correct. Answer the question inside the MembershipCard class.
@Entity
@Table(name = "membership_card")
public class MembershipCard {
@Entity
@Table(name = "student")
public class Student {
@Id
protected int id;
...
}
Question 7 options:
@Entity
@Table(name = "student")
public class Student {
// What annotation describes the relationship here?
@Entity
@Table(name = "membership_card")
...
Question 8 options:
Question 9 (1 point)
Saved
What annotations are needed on the owner field in BankAccount class so we can join the bank_account table
with the person table? Assume that the owner column in the bank_account table is the foreign key to
the person table whose primary key is id.
@Entity
@Table(name = "bank_account")
...
public class BankAccount implements Serializable {
protected Person owner;
...
}
@Entity
@Table(name = "person")
...
public class Person implements Serializable {
@Id
protected int id;
...
}
Question 9 options:
a) @OneToOne(fetch = FetchType.LAZY)
b) @ManyToMany(fetch = FetchType.LAZY)
e) @OneToMany(fetch = FetchType.LAZY)