| 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: 14672
|
|
|
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: 14672
|
|
|
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
|
 |
 |
|
|
subject: A entity question
|
|
|