Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mock Question about @ManyToOne and @OneToOne

 
Benoît de Chateauvieux
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have a doubt with this question from mock exam:

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?

A-
@Entity Celery {
/* ... */
}
@Entity Carrot {
@ManyToOne
Celery celery;
/* ... */
}

B-
@Entity Celery {
@ManyToOne
Carrot carrot;
/* ... */
}
@Entity Carrot {
/* ... */
}

C-
@Entity Celery {
@OneToOne
Carrot carrot;
/* ... */
}
@Entity Carrot {
/* ... */
}

D-
@Entity Celery {
/* ... */
}
@Entity Carrot {
@OneToOne
Carrot carrot;
/* ... */
}


The right answer is B but I think C is a possibility too.
Your opinion ?
Thanks

Beno�t
 
Prabhat Kumar
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please tell me that where did you take this mock exam from ? I am also preparing for SCBCD5.0 but not getting mock exam.Can you help me??

Thanks in advance..
Prabhat
 
Vivaldo Pinto
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My opinion is the letter B.

Thanks for your question.
[ October 23, 2007: Message edited by: Vivaldo Pinto ]
 
Hanuma Deepak Muvvala
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Beno�t,

Yes, both B and C entities are accurately model to DB.

Thanks,
Deepak.......
 
Sohail Naseem
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
B is the correct answer.

C cannot be answer. See ejb3 persistence spec (2.1.8.3.1 Unidirectional OneToOne Relationships).

"Assuming that:
Entity A references a single instance of Entity B.
Entity B does not reference Entity A.
A unidirectional relationship has only an owning side, which in this case must be Entity A.
Entity A is mapped to a table named A.
Entity B is mapped to a table named B.
Table A contains a foreign key to table B. The foreign key column name is formed as the concatenation
of the following: the name of the relationship property or field of entity A; "_"; the
name of the primary key column in table B. The foreign key column has the same type as the
primary key of table B and there is a unique key constraint on it."

The question says there is no constraint on the Celery table.
[ October 25, 2007: Message edited by: Sohail Naseem ]
 
Gustavo Castellano
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i didnt get it !! =//.

can you explain again ?
 
Hanuma Deepak Muvvala
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sohail,
If it is the case even @ManyToOne has same constarint on foreign key like

"Table A contains a foreign key to table B. The foreign key column name is formed as the concatenation
of the following: the name of the relationship property or field of entity A; "_"; the
name of the primary key column in table B. The foreign key column has the same type as the
primary key of table B." refer to section 2.1.8.3.2 of ejb-3_0-fr-spec-persistence.

so for my knowledge Both B,C are correct.
Correct me If I am wrong.

Thanks,
Deepak
 
Benoît de Chateauvieux
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi hanumadeepak muvvala,

So, the difference is the UNIQUE constraint of the One-To-One relation.
I think this could be a good reason to prefer the answer B.
Thanks to all.

Beno�t
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic