首页 > 开发 > 综合 > 正文

query must begin with SELECT or FROM: delete

2024-07-21 02:51:30
字体:
来源:转载
供稿:网友

在执行语句:

getHibernateTemplate().bulkUpdate("delete RoleModuleRight where module_id=? and role_id=?", new Object[] { module_id, role_id });

时报错:

[ERROR] http-aPR-8080-exec-18 2017-03-02 11:24:49,405 com.fsti.rbac.action.RbacAction - org.springframework.orm.hibernate3.HibernateQueryException: query must begin with SELECT or FROM: delete [delete RoleModuleRight where module_id=? and role_id=?]; nested exception is org.hibernate.QueryException: query must begin with SELECT or FROM: delete [delete RoleModuleRight where module_id=? and role_id=?]

百度到的解决方案一般为: hibernate 配置文件hibernate.cfg.xml里 解析hibernate 查询语言为2.X版本,将其改为3.X版本。 修改解析hibernate查询语言版本 但是在按网络上的方法找到hibernate 配置文件hibernate.cfg.xml后,打开文件时提示: this project is not a Myeclipse Hibernate project.Assuming Hibernate 3 capabilites for the configuration editor 并没有在文件中找到解析查询语句的配置语句。 因此,就直接在file search中查找<prop key="hibernate.query.factory_class">

Hibernate配置是被写在了applicationContext.xml文件中:

配置文件

将文件中的

<prop key="hibernate.query.factory_class"> org.hibernate.hql.classic.ClassicQueryTranslatorFactory </prop>

修改为:

<property name="hibernate.query.factory_class"> org.hibernate.hql.ast.ASTQueryTranslatorFactory </property>

重启服务器之后报错:

[ERROR] localhost-startStop-1 2017-03-02 14:52:02,293 org.springframework.web.context.ContextLoader - Context initialization failedorg.springframework.beans.factory.BeanDefinitionStoreException: Line 172 in XML document from ServletContext resource [/WEB-INF/classes/config/spring/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException: The content of element type "property" must match "(description?,(bean|ref|idref|value|null|list|set|map|props)?)".org.xml.sax.SAXParseException: The content of element type "property" must match "(description?,(bean|ref|idref|value|null|list|set|map|props)?)". at org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1213) at org.apache.xerces.validators.common.XMLValidator.reportRecoverableXMLError(XMLValidator.java:1851) at org.apache.xerces.validators.common.XMLValidator.callEndElement(XMLValidator.java:1495) at org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocumentScanner.java:1204) at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381) at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1098) at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:195) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:222) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:173) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:148) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:126) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:142) at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:126) at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94) at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:89) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:269) at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:134) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49) at com.fsti.util.helper.SpringContextLoader.contextInitialized(SpringContextLoader.java:13) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4887) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5381) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1114) at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1672) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619)2017-3-2 14:52:02 org.apache.catalina.core.StandardContext listenerStart严重: Exception sending context initialized event to listener instance of class com.fsti.util.helper.SpringContextLoader

错误信息的大意为:标签格式不符合规定。也就是,在这个配置文件中,property配置所用的标签是prop和key,而不是property和name。 因此,将语句修改为:

<prop key="hibernate.query.factory_class"> org.hibernate.hql.ast.ASTQueryTranslatorFactory </prop>

即可通过编译。

使用delete语句不再报错。


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表