我得到以下错误
org.hibernate.hql.internal.ast.QuerySyntaxException:意外标记值:第 1 行附近的值,第 161 列。
[insert into shop_information(storeName, ownername, license, email, dlnumber, gst, pan, pincode, phonenumber, mobile, fax, cst, phone, district, state, country) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]
你必须使用
session.createSQLQuery(SQL_QUERY);
不
session.createQuery(SQL_QUERY);
HQL 仅支持从另一个表插入。
例如
INSERT INTO Entity properties_list select_statement.
如果您不想使用标准插入语句,例如
INSERT INTO Table properties_list values ( :vals)
你需要
session.createSQLQuery(SQL_QUERY)
编辑,以回答评论:
我认为参数是从 0 开始的,所以尝试从 0 开始参数:
query.setParameter(0,storeName);
query.setParameter(1,ownerName);
etc...
但是,更好的方法是使用命名参数:
sessionFactory.getCurrentSession()
.createSQLQuery("update table set field = 1 where id = :id")
.setParameter("id", someId)
.executeUpdate();