hibernate错误:could not execute native bulk manipulation query

今天在写一个hibernate的更新操作

String hql="update "+list.get(1)+" set "+columnName+"="+list.get(3)+" where "+list.get(1)+"id="+list.get(0);

Query q=se.createQuery(hql);q.executeUpdate();tr.commit();

se.close();

遇到了如下错误:xception in thread "AWT-EventQueue-0" org.hibernate.exception.SQLGrammarException: could not execute update queryat org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:110)at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:421)at org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:283)at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1169)at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:117)at service.UpdataService.update(UpdataService.java:56)at frame.listener.TableListener.tableChanged(TableListener.java:50)at javax.swing.table.AbstractTableModel.fireTableChanged(AbstractTableModel.java:280)at javax.swing.table.AbstractTableModel.fireTableCellUpdated(AbstractTableModel.java:259)at frame.model.TableModel.setValueAt(TableModel.java:56)at javax.swing.JTable.setValueAt(JTable.java:2719)at javax.swing.JTable.editingStopped(JTable.java:4721)at javax.swing.AbstractCellEditor.fireEditingStopped(AbstractCellEditor.java:125)at javax.swing.DefaultCellEditor$EditorDelegate.stopCellEditing(DefaultCellEditor.java:350)at javax.swing.DefaultCellEditor.stopCellEditing(DefaultCellEditor.java:215)at javax.swing.JTable$GenericEditor.stopCellEditing(JTable.java:5475)at javax.swing.plaf.basic.BasicTableUI$Handler.mousePressed(BasicTableUI.java:986)at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:263)at java.awt.Component.processMouseEvent(Component.java:6213)at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)at java.awt.Component.processEvent(Component.java:5981)at java.awt.Container.processEvent(Container.java:2041)at java.awt.Component.dispatchEventImpl(Component.java:4583)at java.awt.Container.dispatchEventImpl(Container.java:2099)at java.awt.Component.dispatchEvent(Component.java:4413)at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4556)at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4217)at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4150)at java.awt.Container.dispatchEventImpl(Container.java:2085)at java.awt.Window.dispatchEventImpl(Window.java:2475)at java.awt.Component.dispatchEvent(Component.java:4413)at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column '??????é??1' in 'field list'at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)at com.mysql.jdbc.Connection.execSQL(Connection.java:3283)at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332)at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1604)at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1519)at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1504)at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:101)... 37 more


上网搜了下,和我的错方式又不一样,后来将生成的sql语句放到mysql中去执行才发现原来构造sql语句的时候发生了错误

String hql="update "+list.get(1)+" set "+columnName+"="+list.get(3)+" where "+list.get(1)+"id="+list.get(0);

原来columnName的赋值需要用单引号

String hql="update "+list.get(1)+" set "+columnName+"=’"+list.get(3)+"' where "+list.get(1)+"id="+list.get(0);

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值