title: difference between hasmany belongsTo , namedQuery belongsTo and hasmany instantiation grails domain
body: <p>In grails, I have two domain classes Question and QuestionOption.One question have many options.Each option has a question.
  I went through 4 different scenario.
  These scenarios has combination of instantiation-namedQuery , belongsTo-namedQuery , instantiation-hasMany and  belongsTo-hasMany.</p>
  
  <pre><code>Scenario 1:
  
  class Question
  {
    String quesText
    static constraints={}
    static namedQueries={
      getAllQuestionOptions{question-&gt;
        return QuestionOption.findAllWhere(question:question)
      }
    }
  }
  
  class QuestionOption
  {
    String optionText
    Question question
    static constraints={}
  }
  </code></pre>
  
  <p>.</p>
  
  <pre><code>Scenario 2:
  class Question
  {
    String quesText
    static constraints={}
    static namedQueries={
      getAllQuestionOptions{question-&gt;
        return QuestionOption.findAllWhere(question:question)
      }
    }
  }
  
  class QuestionOption
  {
    String optionText
    static constraints={}
    static belongsTo=[question:Question]
  }
  </code></pre>
  
  <p>.</p>
  
  <pre><code>Scenario 3:
  class Question
  {
    String quesText
    static constraints={}
    static hasMany=[questionOption:QuestionOption] 
  }
  
  class QuestionOption
  {
    String optionText
    Question question
    static constraints={}
  }
  </code></pre>
  
  <p>.</p>
  
  <pre><code>Scenario 4:
  class Question
  {
    String quesText
    static constraints={}
    static hasMany=[questionOption:QuestionOption] 
  }
  
  class QuestionOption
  {
    String optionText
    static constraints={}
    static belongsTo=[question:Question]
  }
  </code></pre>
  
  <p>I used all these scenarios with mysql and all resulted with same schema</p>
  
  <pre><code>mysql&gt; desc question;
  +-------------+--------------+------+-----+---------+----------------+
  | Field       | Type         | Null | Key | Default | Extra          |
  +-------------+--------------+------+-----+---------+----------------+
  | id          | bigint(20)   | NO   | PRI | NULL    | auto_increment |
  | version     | bigint(20)   | NO   |     | NULL    |                |
  | ques_text   | varchar(255) | NO   |     | NULL    |                |
  +-------------+--------------+------+-----+---------+----------------+
  3 rows in set (0.00 sec)
  
  mysql&gt; desc question_option;
  +-------------+--------------+------+-----+---------+----------------+
  | Field       | Type         | Null | Key | Default | Extra          |
  +-------------+--------------+------+-----+---------+----------------+
  | id          | bigint(20)   | NO   | PRI | NULL    | auto_increment |
  | version     | bigint(20)   | NO   |     | NULL    |                |
  | option_text | varchar(255) | NO   |     | NULL    |                |
  | question_id | bigint(20)   | NO   | MUL | NULL    |                |
  +-------------+--------------+------+-----+---------+----------------+
  </code></pre>
  
  <p>What is difference between using these scenarios in the terms of cascading , unidirectional-bidirectional and aggregation-composition?
  Bidirectional means when both entity knows about each other.Unidirectional means first entity know about second but reverse is not true.
  To understand cascading I referred this: <a href="http://www.mkyong.com/hibernate/hibernate-cascade-example-save-update-delete-and-delete-orphan/" rel="nofollow">http://www.mkyong.com/hibernate/hibernate-cascade-example-save-update-delete-and-delete-orphan/</a> .
  Please help</p>