This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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?
C cannot be answer. See ejb3 persistence spec (184.108.40.206.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 ]
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 220.127.116.11.2 of ejb-3_0-fr-spec-persistence.
so for my knowledge Both B,C are correct. Correct me If I am wrong.
Benoît de Chateauvieux
Joined: Aug 10, 2007
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.