问题描述
我正在使用java-hibernate-mysql组合
当我在更新查询时遇到以下错误。我不明白hibernate有什么问题。
以下我发布了我得到的错误:
org.hibernate.QueryException:并非所有命名参数都已set:[0] [update sequence s set s.cmd_output ='neox tty1 2012-06-08 09:40(:0)
neox pts / 1 2012-06-08 09:41(:0)
neox pts / 0 2012-06-08 09:41(:0)
neox pts / 2 2012-06-08 09:41(:0)
neox pts / 3 2012-06 -08 12:48(deval-PC.local.lan)
[neox @ localhost〜] $',s.cmd_output_time ='2012-06-08 12:48:58'where s.id = 43]
at org.hibernate.impl.AbstractQueryImpl.verifyParameters(AbstractQueryImpl.java:106)
at org.hibernate.impl.QueryImpl.executeUpate(QueryImpl.java:85)
at db_model.sequence_db .insert_Sequence_new(sequence_db.java:242)
at views.CaptureNavigationView $ 10.widgetSelected(CaptureNavigationView.java:555)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:240)在org.eclipse.swt.widgets.EventTable.sendEvent处为
(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java :4165)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
at org.eclipse.ui.internal.Workbench.access $ 4(Workbench.java:2494)
在org.eclipse.ui.internal.Workbench $ 7.run(Workbench.java:674)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at nspl.test.ui. Application.start(Application.java:43)
在org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
在org.eclipse.core.runtime.internal。 adaptor.EclipseAppLauncher.runAppli (EclipseAppLaunch er.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor .EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native方法)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown源)
在org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
在org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
有谁可以告诉我为什么即时通讯出现此错误?
你正在执行一个SQL字符串中有:
字符吗?如果是这样,Hibernate期待一个参数,你不设置它。
字符串sql =更新SomeTable设置someColumn =:值;
使用这个函数,您通常会使用
$ b $设置值参数b
SQLQuery query = getSession()。createSQLQuery(sql);
query.setString(value,Some value with:in it);
或类似。我只能假设你的值有一个:
,它不代表一个参数,所以你应该把它作为一个字符串并将其设置为参数。
I am using java-hibernate-mysql combination
When i m doing update query i m getting following error. I don't understand what is wrong with hibernate.Following i have posted the error which i m getting :
org.hibernate.QueryException: Not all named parameters have been set: [0] [update sequence s set s.cmd_output='neox tty1 2012-06-08 09:40 (:0)
neox pts/1 2012-06-08 09:41 (:0)
neox pts/0 2012-06-08 09:41 (:0)
neox pts/2 2012-06-08 09:41 (:0)
neox pts/3 2012-06-08 12:48 (deval-PC.local.lan)
[neox@localhost ~]$ ', s.cmd_output_time='2012-06-08 12:48:58' where s.id=43]
at org.hibernate.impl.AbstractQueryImpl.verifyParameters(AbstractQueryImpl.java:106)
at org.hibernate.impl.QueryImpl.executeUpate(QueryImpl.java:85)
at db_model.sequence_db.insert_Sequence_new(sequence_db.java:242)
at views.CaptureNavigationView$10.widgetSelected(CaptureNavigationView.java:555)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:240)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at nspl.test.ui.Application.start(Application.java:43)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLaunch er.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Can anybody tell me why i m getting this error?
Are you executing an sql string with the :
character in them? If so, Hibernate is expecting a parameter and you're not setting it.
String sql = "update SomeTable set someColumn = :value";
Using this you would usually set the value parameter using
SQLQuery query = getSession().createSQLQuery(sql);
query.setString("value", "Some value with : in it");
or similar. I can only assume your value has a :
in it which does not signify a parameter so you should build this as a string and set that as the parameter.
这篇关于如何解决“org.hibernate.QueryException:并非所有的命名参数都已设置”错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!