title: Hibernate: insert in entity using select with named parameters
body: <p>I have a very specific problem in which I must do something like (in HQL):</p>
  
  <pre><code>insert into EntityA(field1, field2, field3, field4, field5)
  select
      :paramForField1, 
      :paramForField2,
      :paramForField3,
      :paramForField4,
      :paramForField5
  from 
      EntityB
  where 
      ...
  </code></pre>
  
  <p>The parameters are being passed using <code>Query.setParameter(String, Object)</code> (<a href="https://docs.jboss.org/hibernate/orm/3.5/api/org/hibernate/Query.html#setParameter(java.lang.String,%20java.lang.Object)" rel="nofollow" title="JavaDoc">JavaDoc</a>) and they are String, String, String, Date and an Enum.</p>
  
  <p>Although the parameter number is right (five parameters for five fields), Hibernate keeps raising the following exception:</p>
  
  <pre><code>...
  Caused by: org.hibernate.QueryException: number of select types did not match those for insert [insert into ...]
      at org.hibernate.hql.ast.tree.IntoClause.validateTypes(IntoClause.java:116)
      at org.hibernate.hql.ast.tree.InsertStatement.validate(InsertStatement.java:57)
      at org.hibernate.hql.ast.HqlSqlWalker.postProcessInsert(HqlSqlWalker.java:701)
      at org.hibernate.hql.antlr.HqlSqlBaseWalker.insertStatement(HqlSqlBaseWalker.java:513)
      at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:255)
      at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:254)
      at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
      at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
      at org.hibernate.engine.query.HQLQueryPlan.&lt;init&gt;(HQLQueryPlan.java:101)
      at org.hibernate.engine.query.HQLQueryPlan.&lt;init&gt;(HQLQueryPlan.java:80)
      at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94)
      at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
      at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
      at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1651)
      ...
  </code></pre>
  
  <p>I'm using Hibernate 3.3.2 GA.</p>
  
  <p>Thanks in advance.</p>