Note that there are some explanatory texts on larger screens.

plurals
  1. PONo foreign key constraints in database.!
    text
    copied!<p>My organization works on Spring MVC with Hibernate. We always specify foreign key constraints in mapping file, like for person and contactList in <code>Person.hbm.xml</code></p> <pre><code>&lt;set name="ContactList"&gt; &lt;key column="PersonId" foreign-key="Fk_Peson_Contact"/&gt; &lt;one-to-many class="Sample.Model.Contact"/&gt; &lt;/set&gt; </code></pre> <p>This mapping will create one-to-many relationship between <code>Person</code> and <code>Contact</code>, and keep <code>PersonID</code> as foreign key column in the <code>Contact</code> table.</p> <p>But, now organization has decided not to mention any kind of relationship in mapping file, means in above case <code>Person</code> mapping will not have any kind of one-to-many mapping instead of this <code>Contact</code> mapping will have property <code>&lt;property name="FK_PersonID"/&gt;</code> which will create column to hold <code>personID</code>. In this scenario table <code>Person</code> and <code>Contact</code> will look same but the difference is their is no relationship between <code>Person</code> and <code>Contact</code> coz no mapping is specified.</p> <p>In such case if we want to fetch person's contactList then we have to fire two queries one to fetch person another for its contactList. let suppose we want to fetch personList with its contactList then we have to <code>For loop</code> on PersonList and fetch its ContactList which will fire number of queries.</p> <p>When i ask why not specify relationship then senior said , </p> <ul> <li><p>If foreign key is in DB then we can't do slicing and partitioning.</p></li> <li><p>When we fire join query DB takes more time to execute it.Which may slow down DB server.</p></li> </ul> <p>But,my question is - </p> <ul> <li><p>if i do <code>For looping</code> on personList then it will fire number of queries to fetch contacts is it feasible?</p></li> <li><p>can such looping slow down application or application server?</p></li> <li><p>what if i want to fetch personList with its conatctList,AddressList,QualificationList, Does this cause n+1 issue?</p></li> </ul> <p><strong>Which Scenario is more beneficial whether to specify mapping or not.</strong> </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload