0% found this document useful (0 votes)
36 views12 pages

Quiz 6 - 2

Uploaded by

rita.jiang889
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views12 pages

Quiz 6 - 2

Uploaded by

rita.jiang889
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Question 1 (1 point)

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:

a) Any operation in the current entity will cascade to phones as well.


b) No such field exists.

c) No operation in the current entity will cascade to phones.

d) Cascade should only be placed in @ManyToOne relationships.

Question 4 (1 point)
Saved
What does mappedBy mean? Please read: @interface OneToMany
@OneToMany(mappedBy = "owningEmployee", cascade = CascadeType.ALL, orphanRemoval = true)
Question 4 options:

a) The field is in the other entity which owns the relationship.

b) No such field exists.

c) Name of the column in the current entity.

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.

c) @MappedSuperclass is optional. It can be used when multiple entities/tables have common


fields/columns.

d) Mapping information in a class with @MappedSuperclass annotation can be overridden in the


subclasses.

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 {

// What annotation describes the relationship here?

protected Student student;


...
}

@Entity
@Table(name = "student")
public class Student {

@Id
protected int id;
...
}

Question 7 options:

a) @JoinColumn(name = "student_id", referencedColumnName = "id")


@ManyToMany(fetch = FetchType.LAZY)

b) @JoinColumn(name = "id", referencedColumnName = "student_ id")


@ManyToOne(fetch = FetchType.LAZY)

c) @JoinColumn(name = "student_id", referencedColumnName = "id")


@ManyToOne(fetch = FetchType.LAZY)

d) @JoinColumn(name = "id", referencedColumnName = "student_ id")


@OneToMany (fetch = FetchType.LAZY)

e) @JoinColumn(name = "student_id", referencedColumnName = "id")


@OneToMany(fetch = FetchType.LAZY)
Question 8 (1 point)
Saved
Assume everything else is correct. Answer the question inside the Student class.

@Entity
@Table(name = "student")
public class Student {
// What annotation describes the relationship here?

protected Set<MembershipCard> membershipCardSet;


...

@Entity
@Table(name = "membership_card")

public class MembershipCard {

...

protected Student student;


...

Question 8 options:

a) @ManyToOne(mappedBy = "student", fetch = FetchType.LAZY)

b) @OneToMany(mappedBy = "student_id", fetch = FetchType.LAZY)

c) @ManyToMany(mappedBy = "student", fetch = FetchType.LAZY)

d) @OneToMany(mappedBy = "student", fetch = FetchType.LAZY)


e) @ManyToOne (mappedBy = "student_id", fetch = FetchType.LAZY)

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)

@JoinColumn(name = "owner", referencedColumnName = "id")

b) @ManyToMany(fetch = FetchType.LAZY)

@JoinColumn(name = "owner", referencedColumnName = "id")


c) @ManyToOne(fetch = FetchType.LAZY)

@JoinColumn(name = "id", referencedColumnName = "owner")

d) @OneToOne(name= "id", fetch = FetchType.LAZY)

@JoinColumn(name = "id", referencedColumnName = "owner")

e) @OneToMany(fetch = FetchType.LAZY)

@JoinColumn(name = "owner", referencedColumnName = "id")

You might also like