title: How to write an insert query in HQL for a class containing components?
body: <p>I am trying to write an <code>INSERT INTO ... SELECT ...</code> query in HQL. However, the class I am inserting contains <code>&lt;component&gt;</code> items in the mapping. For example, my class definition could be:</p>
  
  <pre><code>public class X
  {
      public virtual string A { get; set; }
      public virtual string B { get; set; }
      public virtual Y C { get; set; }
  }
  public class Y
  {
      public virtual string C1 { get; set; }
      public virtual string C2 { get; set; }
  }
  </code></pre>
  
  <p>And a possible mapping:</p>
  
  <pre><code>&lt;class name="X"&gt;
      &lt;id type="int"&gt;&lt;generator class="identity"/&gt;&lt;/id&gt;
      &lt;property name="A" /&gt;
      &lt;property name="B" /&gt;
          &lt;component name="C"&gt;
              &lt;property name="C1" column="C1" /&gt;
              &lt;property name="C2" column="C2" /&gt;
          &lt;/component&gt;
      &lt;/component&gt;
  &lt;/class&gt;
  </code></pre>
  
  <p>How do I write an insert query for this class in HQL? I tried:</p>
  
  <pre><code>session.CreateQuery("INSERT INTO X(A, B, C1, C2) SELECT A, B, 'foo', 'bar' FROM X data")
         .ExecuteUpdate();
  </code></pre>
  
  <p>This gives the error: </p>
  
  <pre><code>NHibernate.QueryException : could not resolve property: C1 of: X
  [INSERT INTO X(A, B, C1, C2) SELECT A, B, "foo", "bar" FROM X data]
  </code></pre>
  
  <p>I also tried:</p>
  
  <pre><code>session.CreateQuery("INSERT INTO X(A, B, C) SELECT A, B, :C FROM X data")
         .SetParameter("C", new Y() { C1 = "foo", C2 = "bar" });
         .ExecuteUpdate();
  </code></pre>
  
  <p>This gives the error:</p>
  
  <pre><code>NHibernate.HibernateException : Could not determine a type for class: Y
  </code></pre>
  
  <p>I also tried:</p>
  
  <pre><code>session.CreateQuery("INSERT INTO X(A, B, C.C1, C.C2) SELECT A, B, 'foo', 'bar' FROM X data")
         .ExecuteUpdate();
  </code></pre>
  
  <p>This gives the error:</p>
  
  <pre><code>NHibernate.Hql.Ast.ANTLR.QuerySyntaxException : Exception of type 'Antlr.Runtime.MismatchedTreeNodeException' was thrown. near line 1, column 21 
  [INSERT INTO X(A, B, C.C1, C.C2) SELECT A, B, "foo", "bar" FROM X data]
  </code></pre>
  
  <p>Any other suggestions?</p>