aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes A entity question 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 "A entity question" Watch "A entity question" New topic
Author

A entity question

Fu Dong Jia
Ranch Hand

Joined: May 23, 2007
Posts: 131

15. There are two tables in a database, Celery and Carrot. Celery contains a foreign key to Carrot. Each table has a primary key, and there are no other constraints on the tables. No descriptors are used, and in the following options each scenario depicts all the mapping information pertaining to the relationship. Which entities accurately model this database scenario?

1,@Entity Celery {
/* ... */
}
@Entity Carrot {
@ManyToOne
Celery celery;
/* ... */
}


2,@Entity Celery {
@ManyToOne
Carrot carrot;
/* ... */
}
@Entity Carrot {
/* ... */
}


3,@Entity Celery {
@OneToOne
Carrot carrot;
/* ... */
}
@Entity Carrot {
/* ... */
}


4,@Entity Celery {
/* ... */
}
@Entity Carrot {
@OneToOne
Carrot carrot;
/* ... */
}



I think 2 and 3 are correct,am i right?


who dare win!<br />SCJP5(94%)|SCWCD5(86%)|SCBCD(100%)|SCEA in progress
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Please quote your sources. Where does this question come from ?


[My Blog]
All roads lead to JavaRanch
Fu Dong Jia
Ranch Hand

Joined: May 23, 2007
Posts: 131
The mock question come form Sun's Free Proficiency Assessment System.
Fu Dong Jia
Ranch Hand

Joined: May 23, 2007
Posts: 131
Why the answer is 2,but not 3?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

3 looks fine. It's an unidirectional OneToOne relationship, so there should be a foreign key in Celery.
Chaminda Amarasinghe
Ranch Hand

Joined: May 17, 2006
Posts: 402
This is how I understood the question (based on the answer)

Question asks to model the entity based on db scenario. That does not say Celery can contain a unique fk of a carrot. That means Different Celerys can contain same fk of a carrot and obviously a celery and also contain a unique fk of carrot too.

If we specify OneToOne, one possible scenario(but has not specified clearly) will be missed. that is the fact about, for different Celery there is no restriction to hold same fk of Carrot.

So I thinks that's why most suitable answer is ManyToOne
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A entity question