File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Mock Question about @ManyToOne and @OneToOne Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Mock Question about @ManyToOne and @OneToOne" Watch "Mock Question about @ManyToOne and @OneToOne" New topic
Author

Mock Question about @ManyToOne and @OneToOne

Benoît de Chateauvieux
Ranch Hand

Joined: Aug 10, 2007
Posts: 183
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


SCJP5 | SCBCD5 | SCEA5 Part 1
Prabhat Kumar
Greenhorn

Joined: Jan 25, 2007
Posts: 27
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

Joined: Sep 01, 2005
Posts: 53
My opinion is the letter B.

Thanks for your question.
[ October 23, 2007: Message edited by: Vivaldo Pinto ]

SCJP|SCWCD|SCEA 5 PT 1/3
Hanuma Deepak Muvvala
Ranch Hand

Joined: Nov 20, 2005
Posts: 158
Hi Beno�t,

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

Thanks,
Deepak.......
Sohail Naseem
Greenhorn

Joined: Oct 22, 2007
Posts: 5
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

Joined: Apr 11, 2006
Posts: 5
i didnt get it !! =//.

can you explain again ?


Gustavo Henrique Castellano<br /> <br />SCBCD 5<br />SCWCD 1.4<br />SCJP 1.4
Hanuma Deepak Muvvala
Ranch Hand

Joined: Nov 20, 2005
Posts: 158
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

Joined: Aug 10, 2007
Posts: 183
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mock Question about @ManyToOne and @OneToOne