2017-10-20 95 views
0

Im getting below error如何使用MySQL Hibernate解决意外的令牌?

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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)] 
+0

邮政法码。 –

+0

这是我的代码 –

+0

也许你正在尝试执行原生sql,但使用创建JPQL/HQL查询的hibernate方法。 –

回答

0

你必须使用

session.createSQLQuery(SQL_QUERY); 

session.createQuery(SQL_QUERY); 

HQL仅支持从另一个表中插入。

例如

INSERT INTO Entity properties_list select_statement. 

如果您wan't使用标准的INSERT语句像

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(); 
+0

获取此错误... org.hibernate.QueryParameterException:超出已声明的有序参数数目的位置。请记住,序号参数是基于1的!位置:17 @Evgeni Dimitrov –

+0

查看我的更新。尝试使用命名参数。 –

+0

再次出错... java.sql.SQLException:不能用executeQuery()发出数据操作语句。 即时通讯使用此类型query.setParameter(0,storeName); –