# 16. A domain model comprises two entities: Dog and Flea. The developer is required to construct these entities so that the Dog and Flea entities are in a unidirectional one-to-many relationship.
# Which statement about implementing this model is NOT correct?
# The @OneToMany annotation must be placed in the Dog entity.
# The @ManyToOne annotation must NOT be used on the Flea entity.
# A join table can be used to implement this relationship.
# The Flea entity will be the owning side of the relationship.
the correct answer is 4. Why 2nd option is incorrect.
Dog has one to many relationship with Flea...that means one dog can have many fleas, that means the Flea table will have the foreign key to the Dog table...(Flea table should have something like dogId, referencing soe Dog)...The table containing the FK is always the owning side of the relationship...so 4 is correct...
3 is not correct because a Join table will(should) only be used if it is a many to many relationship....but here it's one to many...
Rahul - I disagree with "3 is not correct because a Join table will(should) only be used if it is a many to many relationship....but here it's one to many... "
If the relationship is a one-to-many, and it's *unidirectional*, you will need a join table.
Otherwise, (from a db perspective) how would you store multiple references to fleas in a single dog row? That doesn't make sense.
I accept that you could put the reference on the flea side, but now you've changed the direction.
As an example, "Mastering EJBs", page 245 says
"One-to-many relationships are also typically set up by a foreign key relationship
in the database. In a unidirectional one-to-many relationship, the
application server automatically generates a join table."
I'll qualify this by saying that I am new to EJB, so welcome correction/explanation if I'm wrong.