我是Hibernate的新手我试图使用hql将数据插入表中。下面是代码。在运行代码时我得到以下异常。我试着谷歌搜索每个人都以同样的方式编写代码。我想我的代码中缺少一些东西
Configuration conf = new Configuration();
conf.configure("hibernate.cfg.xml");
SessionFactory factory = conf.buildSessionFactory();
Session session = factory.openSession();
Transaction txn = session.beginTransaction();
Query qry = session.createQuery("INSERT INTO Item (userName, age, id)"+" SELECT e.userName, e.age, e.id from Employee e ");
//qry.setParameter(0, 1);
int res = qry.executeUpdate();
txn.commit();
例外:
Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxError: unexpected token: INSERT near line 1, column 1 [INSERT INTO Item (userName, age, id)
Caused by: line 1:1: unexpected token: INSERT