exam questions

Exam 1z0-898 All Questions

View all questions & answers for the 1z0-898 exam

Exam 1z0-898 topic 1 question 17 discussion

Actual exam question from Oracle's 1z0-898
Question #: 17
Topic #: 1
[All 1z0-898 Questions]

Given two entities with one to-one association:
@Entity public class Person {
@Id Integer id;

}
@Entity public class PersonDetail {
@Id Integer id;

}
Which code fragment correctly defines the detail field that PersonDetail instance in removed if the person instance that references it is removed?

  • A. @OneToOne (optional = false) personDetail detail;
  • B. @OneToOne (optional = false) @mapsId PersonDetail Detail;
  • C. @ OneToOne (orphanremoval = true) PersonDetail Detail;
  • D. @ OneToOne (cascade = ORPHAN _ DELETE) @mapsId
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️
Orphan Removal in Relationships -
When a target entity in one-to-one or one-to-many relationship is removed from the relationship, it is often desirable to cascade the remove operation to the target entity. Such target entities are considered "orphans," and the orphanRemoval attribute can be used to specify that orphaned entities should be removed. For example, if an order has many line items and one of them is removed from the order, the removed line item is considered an orphan. If orphanRemoval is set to true, the line item entity will be deleted when the line item is removed from the order.
The orphanRemoval attribute in @OneToMany and @oneToOne takes a Boolean value and is by default false.
The following example will cascade the remove operation to the orphaned customer entity when it is removed from the relationship:
@OneToMany(mappedBy="customer", orphanRemoval="true")
public List<Order> getOrders() { ... }
Reference: Orphan Removal in Relationships

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Currently there are no comments in this discussion, be the first to comment!
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...