File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A entity question

 
Fu Dong Jia
Ranch Hand
Posts: 131
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please quote your sources. Where does this question come from ?
 
Fu Dong Jia
Ranch Hand
Posts: 131
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The mock question come form Sun's Free Proficiency Assessment System.
 
Fu Dong Jia
Ranch Hand
Posts: 131
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why the answer is 2,but not 3?
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
3 looks fine. It's an unidirectional OneToOne relationship, so there should be a foreign key in Celery.
 
Chaminda Amarasinghe
Ranch Hand
Posts: 404
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic