title: Copy data from one table to other using Hibernate
body: <pre><code>import javax.persistence.Query;
  import org.springframework.stereotype.Repository;
  import org.springframework.transaction.annotation.Transactional;
  
  public int insert() {
      StringBuilder buf = new StringBuilder();
      buf.append(&quot;INSERT INTO EmployeeGroup SELECT * FROM Employee&quot;);
      Query query = getEntityManager().createQuery(buf.toString());
      return query.executeUpdate();
  }
  </code></pre>
  <p>Getting error   &quot;INSERT INTO EmployeeGroup SELECT * FROM Employee&quot;</p>
  <p>Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: expecting OPEN, found 'SELECT' near line 1, column 36 [INSERT INTO EmployeeGroup SELECT * FROM Employee]
  at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:91) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
  at org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:109) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
  at org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:304) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
  at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:203) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
  at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:158) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
  at org.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.java:131) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
  at org.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.java:93) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
  at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:167) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
  at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:301) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
  at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:236) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
  at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1836) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]
  at org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:328) ~[hibernate-entitymanager-4.3.10.Final.jar:4.3.10.Final]
  ... 30 common frames omitted</p>