aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Sun Assessment Exam Question 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Sun Assessment Exam Question 2" Watch "Sun Assessment Exam Question 2" New topic
Author

Sun Assessment Exam Question 2

Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 845
# 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.


SCJP 1.4, SCWCD 5, SCBCD 5, OCPJWSD 5,SCEA-1, Started Assignment Part 2
My blog- http://rkydesigns.blogspot.com
Rahul Babbar
Ranch Hand

Joined: Jun 28, 2008
Posts: 210
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 Babbar
Manish Shah
Greenhorn

Joined: Jun 09, 2002
Posts: 22
the structure will look like this

@Entity
public class Dog{
...
private Collection<Flea> flea=new ArrayList<Flea>();

@One to Many
@JoinColumn(name="FLEA_ID")
public Collection<Flea> getFlea(){
return flea;
}

...
}

@Entity
public class Flea{
...

}

No need of having mapping information in Flea class since this is unidirectional.

Dog class is the owner side since it is annotated by @JoinColumn.

This approach can also be implemented by join tables.

@Entity
public class Dog{
...
private Collection<Flea> flea=new ArrayList<Flea>();

@One to Many
@JoinTable(name="DOG_FLEA"),
joinColumns{@JoinColumn(name="DOG_ID")},
inverseJoinColumns={@JoinColumn(name="FLEA_ID")}
)
public Collection<Flea> getFlea(){
return flea;
}

...
}




SCBCD5, SCWCD, SCJP, MCP
Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 845
Thank's Rahul for your reply.

Sorry i want to actually tell, 2nd is the right answer. I inculded the question as also answer. So that's my numbering changed.


anyway, read the question clearfully

Which statement about implementing this model is NOT correct?


# The Flea entity will be the owning side of the relationship.


it is asking which is not correct. but 4th is correct statement. so 2nd should be the answer.
Mark Garland
Ranch Hand

Joined: Nov 11, 2006
Posts: 226
Hi,

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.

Cheers,

MG


28/06/06 - SCJP - 69%, 05/06/07 - SCWCD - 92%, 28/02/08 - IBM DB2 v9 Fundamentals (Exam 730) - 87%, 18/11/08 - IBM DB2 v9 DBA (Exam 731) - 89%, 26/02/11 - SCBCD - 88%
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Sun Assessment Exam Question 2