我正在使用 hibernate,并且必须进行大量插入,我正在使用本机 sql 查询进行批量插入。但我在尝试执行代码时遇到了问题。为了简单起见,所附代码中的查询只有一条记录。
query= "replace into isbn_reject_data (update_type, isbn13,rejection_reasons,seller_code ,publisher_name,publication_date,age_range,sub_genre,product_category,navigation_category, image_url,rejection_type,title,supc ,authors, language, isbn10, binding, description,pages, price, length, breadth, height, weight, bisac_code, binding_code, language_code) values('edit','9780217445177','BISAC value is invalid, BISAC value is invalid',null,'General Books','2012','',null,null,null,null,'data','Bibliotheca Anti-Quakeriana; Or, a Catalogue of Books Adverse to the Society of Friends. Or, a Catalogue of Books Adverse to the Society of Friends',null,'Joseph Smith','English','0217445179','Paperback','description{m',206,2894,1,19,25,374,'','BC','eng')"
session.getCurrentSession().createSQLQuery(query).executeUpdate();
Run Code Online (Sandbox Code Playgroud)
查询中的大括号 ( { ) 会产生问题,因为它是一个特殊字符。解决方法是使用 HQL 和 setParemeter 方法。但我无法使用它,因为我必须进行多次插入。
堆栈跟踪:
Unmatched braces for alias path [replace into isbn_reject_data (update_type, isbn13,rejection_reasons,seller_code …Run Code Online (Sandbox Code Playgroud)