exam questions

Exam 1z0-898 All Questions

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

Exam 1z0-898 topic 1 question 26 discussion

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

The department entity has a unidirectional OneToMany relationship to the employee entity. The developer wants to model this relationship as a java.util.map such that the key of map is true employee name. The primary key of the Employees entity is empId, an integer.
Which of the following is correct?

  • A. @OneToMany (targetEntity = Employee.class) @MapKeyClass (string.class) map employees;
  • B. @OneToMany @mapKey (name = "name") map < integer, Employee> Employees;
  • C. @OneToMany @MapKeyJoinColumn (name = "name") map <String, Employee> employees;
  • D. @OneToMany @mapsId (name = "name") map <String, Employee> employees;
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️
Annotation Type MapKey specifies the map key for associations of type java.util.Map when the map key is itself the primary key or a persistent field or property of the entity that is the value of the map.
Example:
@Entity
public class Department {
...
@OneToMany(mappedBy="department")
@MapKey(name="name")
public Map<String, Employee> getEmployees() {... }
...
}
@Entity
public class Employee {
@Id public Integer getEmpId() { ... }
...
@ManyToOne
@JoinColumn(name="dept_id")
public Department getDepartment() { ... }
...
}

Reference: javax.persistence, Annotation Type MapKey

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 ...