wood burning stoves 2.0*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Mock Questions About @OneToOne and @ManyToOne 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 "Mock Questions About @OneToOne and @ManyToOne" Watch "Mock Questions About @OneToOne and @ManyToOne" New topic
Author

Mock Questions About @OneToOne and @ManyToOne

Fofa He
Greenhorn

Joined: Jun 28, 2007
Posts: 5
Hi guys, could you help me with the following question?
I am confused by B and C. I think there is nothing wrong with C, regarding syntax/restriction/specification. The only reason we should choose B instead of C ,is that B makes more sense in reallife ,right? Or have i mistaken ?Please correct me if i was wrong. Thanks in advance!

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?

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;
/* ... */
}
[ December 14, 2007: Message edited by: Fofa He ]

SCJP5 (95%)<br />SCBCD5 (96%)<br />SCEA (Preparing...)
Satya Maheshwari
Ranch Hand

Joined: Jan 01, 2007
Posts: 368
Only answer b is correct due to the below reason:

Each table has a primary key, and there are no other constraints on the tables.


For answer C to be correct, it was mandatory that the foreign key had a unique constraint on it.


Thanks and Regards
Gotan itain Lasgo
Greenhorn

Joined: Dec 10, 2007
Posts: 12
What mean "no other constraint" ??

Can you give me some example where I use "other constraint" so I can use OneToOne ??
Fofa He
Greenhorn

Joined: Jun 28, 2007
Posts: 5
For answer C to be correct, it was mandatory that the foreign key had a unique constraint on it.

Hi Satya, I haven't found the unique restriction stated in spec, and I haven't found it in generated sql(Container is JBoss AS 4.2.1.GA)...So I am still a little confused...
But anyway,thanks for your help!It is the best answer for me now
Satya Maheshwari
Ranch Hand

Joined: Jan 01, 2007
Posts: 368
Quoting from persistence spec 2.1.8.1

Bidirectional OneToOne Relationships
Assuming that:
Entity A references a single instance of Entity B.
Entity B references a single instance of Entity A.
Entity A is specified as the owner of the relationship.
The following mapping defaults apply:
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.


I hope the text marked in bold should clarify.
Fofa He
Greenhorn

Joined: Jun 28, 2007
Posts: 5
Satya,thanks for your help!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mock Questions About @OneToOne and @ManyToOne
 
Similar Threads
JPA Multiple Foreign Key Join
Answers of Sun's Free Proficiency Assessment
A entity question
Sun Assessment Exam Question
Mock Question about @ManyToOne and @OneToOne