About Question enthuware.oce-jpad.v6.2.526 :

Moderator: admin

M_Z

About Question enthuware.oce-jpad.v6.2.526 :

Post by M_Z » Mon Mar 12, 2012 3:40 pm

I don't see "mappedBy" attribute on any of annotations, so it's impossible to create a single two-direction relationship. Instead two single-directional relationships can be created.

admin
Site Admin
Posts: 7451
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.526 :

Post by admin » Mon Mar 12, 2012 7:02 pm

While what you are saying is correct, the question does not ask to create single bidirectional. To satisfy the requirement given in the question, mappedBy is not necessary.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

johnlong
Posts: 185
Joined: Mon Jun 20, 2016 5:06 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.526 :

Post by johnlong » Wed Dec 21, 2016 7:10 pm

Could you please advise why

Code: Select all

@Entity
public class Employee
@OneToOne
private Department department;
Does not satisfy requirement of Employee having only one department and @ManyToOne is required.

admin
Site Admin
Posts: 7451
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.526 :

Post by admin » Fri Dec 23, 2016 12:16 am

When you apply @OneToOne to department, it means that Employee refers to one Department (which is ok) and Department refers to one Employee (which is not ok). The question clearly says that a Department can have any number of Employees. That is why you need ManyToOne on department variable.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

johnlong
Posts: 185
Joined: Mon Jun 20, 2016 5:06 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.526 :

Post by johnlong » Fri Dec 23, 2016 2:58 pm

But it's possible to have one to one from Employee to Department, and many to one from Department to Employee (2 unidirectional relationships)

admin
Site Admin
Posts: 7451
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.526 :

Post by admin » Fri Dec 23, 2016 10:26 pm

Not sure I understand what you mean. There cannot be as many departments as employees. So a OneToOne in Employee on department variable wouldn't make any sense.
If you like our products and services, please help us by posting your review here.

johnlong
Posts: 185
Joined: Mon Jun 20, 2016 5:06 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.526 :

Post by johnlong » Sat Dec 24, 2016 6:11 pm

Ok, I will try to explain my point :

Code: Select all

@Entity
public class Employee

@OneToOne  // Requirement 1 of 2 is fulfilled "An employee can work in only one department"
private Department Department

Code: Select all

@Entity
public class Department

@OneToMany  // Requirement 2 of 2 is fulfilled "Department can have any number of Employees"
private Collection<Employee> employees
Those are two unidirectional associations (Problem does not say that it has to be bidirectional relationship)

admin
Site Admin
Posts: 7451
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.526 :

Post by admin » Sun Dec 25, 2016 12:16 pm

But the first part of your example i.e. @OneToOne also implies that in this relationship a Department has one employee, which is not given in the problem statement.
Your example implies that there are two relationships between Employee and Departement, which is not given in the problem statement. I understand that you are interpreting it that way but that interpretation is too convoluted. You should go with the most obvious interpretation that there is only one relationship between them.

thank you,
Paul.
If you like our products and services, please help us by posting your review here.

johnlong
Posts: 185
Joined: Mon Jun 20, 2016 5:06 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.526 :

Post by johnlong » Sun Dec 25, 2016 6:17 pm

But if there is only one relationship (bidirectional relationship) then one side has to be owning, and inverse side has to add mappedBy element, but it does not.

admin
Site Admin
Posts: 7451
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.526 :

Post by admin » Mon Dec 26, 2016 12:54 am

Yes, you are right. Your solution is technically correct. It just doesn't feel right though and I can't pin point the reason why :oops:
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests