我正在使用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();
查询中的大括号( {)正在创建问题,因为它是一个特殊字符。解决方法是使用HQL和setParemeter方法。但我不能使用它,因为我必须进行多次插入。
堆栈跟踪:
Unmatched braces for alias path [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')]
org.hibernate.loader.custom.sql.SQLQueryParser.substituteBrackets(SQLQueryParser.java:74)
org.hibernate.loader.custom.sql.SQLQueryParser.process(SQLQueryParser.java:51)
org.hibernate.loader.custom.sql.SQLCustomQuery.<init>(SQLCustomQuery.java:110)
org.hibernate.engine.query.NativeSQLQueryPlan.<init>(NativeSQLQueryPlan.java:43)
org.hibernate.engine.query.QueryPlanCache.getNativeSQLQueryPlan(QueryPlanCache.java:114)
org.hibernate.impl.AbstractSessionImpl.getNativeSQLQueryPlan(AbstractSessionImpl.java:137)
org.hibernate.impl.SessionImpl.executeNativeUpdate(SessionImpl.java:1155)
org.hibernate.impl.SQLQueryImpl.executeUpdate(SQLQueryImpl.java:302)
com.snapdeal.IngramIntegration.db.dao.impl.BooksDaoImpl.saveBooksByQuery(BooksDaoImpl.java:155)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
com.sun.proxy.$Proxy24.saveBooksByQuery(Unknown Source)
com.snapdeal.IngramIntegration.classes.Test.save(Test.java:115)
com.snapdeal.IngramIntegration.classes.Test.main(Test.java:90)
答案 0 :(得分:0)
.. LIKE UPPER(:searchString).... 。 。 query.setString(“ searchString”,“%” + searchString +“%”); 这对我有用!