2 zhanhualei2008 zhanhualei2008 于 2013.10.21 11:06 提问

org.hibernate.exception.SQLGrammarException: could not insert:

用的框架 Struts2+Hibernate3+Spring3
数据库为:SQLServer2005
环境是:Myeclipse8.5 服务器为:apache-tomcat-8.0.0-RC1
问题:在我尝试通过struts2 action向数据库插入数据是出现异常。
异常信息如下:
Struts Problem Report
Struts has detected an unhandled exception:

Messages: '107' ????????
could not insert: [com.gxwz.entity.GxUser]
could not insert: [com.gxwz.entity.GxUser]; SQL [insert into 107gxwz.dbo.gx_user (UName, UPwd, UGender, UEmal, URole, UHead, URegDate, ULastLogin, ULastEmit, UPermit, UMobile, UUploadFilesIDs, UDownLoadFileIDs, UUrl, UTopicIDs, URevertIDs) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]; nested exception is org.hibernate.exception.SQLGrammarException: could not insert: [com.gxwz.entity.GxUser]

File: com/microsoft/sqlserver/jdbc/SQLServerException.java
Line number: 216


Stacktraces
org.springframework.dao.InvalidDataAccessResourceUsageException: could not insert: [com.gxwz.entity.GxUser]; SQL [insert into 107gxwz.dbo.gx_user (UName, UPwd, UGender, UEmal, URole, UHead, URegDate, ULastLogin, ULastEmit, UPermit, UMobile, UUploadFilesIDs, UDownLoadFileIDs, UUrl, UTopicIDs, URevertIDs) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]; nested exception is org.hibernate.exception.SQLGrammarException: could not insert: [com.gxwz.entity.GxUser]
org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:629)
org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)
org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:683)
com.gxwz.dao.impl.UserDaoImpl.add(UserDaoImpl.java:30)
com.gxwz.service.impl.UserServiceImpl.add(UserServiceImpl.java:35)
com.gxwz.action.UserAction.addUser(UserAction.java:47)
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)
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441)
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:130)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:165)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:179)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:223)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:107)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:75)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:934)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:90)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:494)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1009)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:632)
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:281)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2248)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2237)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:724)

org.hibernate.exception.SQLGrammarException: could not insert: [com.gxwz.entity.GxUser]
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:64)
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2176)
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2656)
org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71)
org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:321)
org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:563)
org.hibernate.impl.SessionImpl.save(SessionImpl.java:551)
org.hibernate.impl.SessionImpl.save(SessionImpl.java:547)
org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:686)
org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:1)
org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:683)
com.gxwz.dao.impl.UserDaoImpl.add(UserDaoImpl.java:30)
com.gxwz.service.impl.UserServiceImpl.add(UserServiceImpl.java:35)
com.gxwz.action.UserAction.addUser(UserAction.java:47)
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)
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441)
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243)
。。。。。。。。。。。。省略。。。。。。
配置文件如下:
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
"http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<!-- hibernate配置开始 -->

<!-- 数据源注入session工厂 -->
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">






org.hibernate.dialect.SQLServerDialect

update




com/gxwz/entity/GxUser.hbm.xml



<!-- 配置数据库连接池开始-->



value="jdbc:sqlserver://localhost:1433;DatabaseName=107gxwz">




<!-- 配置数据库连接池结束-->
<!-- 声明事物管理器 -->
class="org.springframework.orm.hibernate3.HibernateTransactionManager">


class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator">









我的实体映射文件如下:





























跪求大虾指点一二。。。。在网上找了好久都没解决。。。。

1个回答

toto_2000061
toto_2000061   2013.10.21 12:19

sql语句写错了吧,insert into 107gxwz.dbo.gx_user (UName, UPwd, 。。。。

107gxwz???

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
org.hibernate.exception.SQLGrammarException: could not insert:XXX解决
环境 MyEclipse 8.6+Hibernate3.2 问题 Hibernate映射报如下错误: org.hibernate.exception.SQLGrammarException: could not insert: [com.oracle.entities.Wife] at org.hibernate.exception.SQLStateConverter
org.hibernate.exception.SQLGrammarException:could not insert:问题解决
今天做SHH的整合,在做底层Hibernate与数据库连接的过程中,运行测试类, 遇到了org.hibernate.exception.SQLGrammarException:could not insert:的问题 控制台显示了SQL代码,但是数据库中没有插入一条数据, 在网上查找有说是数据库表中字段名与Hibernate关键字重复的, 仔细检查报错代码发现是控制台中显示的|SQL语句中
关于org.hibernate.exception.SQLGrammarException: could not insert:
在部署hibernate项目时,出现如下错误: Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not insert: [com.hibernate.domain.User] at org.hibernate.exception.SQLStateConverter.convert(SQL
hibernate.exception.SQLGrammarException异常:could not insert、
人生的第一篇CSDN文章,给了hibernate,第一次写hibernate示例就
“org.hibernate.exception.SQLGrammarException: could not insert...”解决方法
HTTP Status 500 - type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception org.springframework.dao.InvalidDa
解决org.hibernate.exception.SQLGrammarException:could not insert
解决org.hibernate.exception.SQLGrammarException:could not insert 在用hibernate做开发时,有时候会遇到org.hibernate.exception.SQLGrammarException:could not insert这样的错误。 错误原因:一般是数据库表中的字段包含了数据库的关键字(保留字) 处理方法:修改
Hibernate: org.hibernate.exception.SQLGrammarException: could not insert: 错误
最近在学习Java Web,今天刚接触Hibernate。学习的书籍是《轻量级Java EE企业应用实战(第3版)》。书中367页5.2.2中给予的Hibernate例子中的代码运行有以下错误: 严重: Exception occurred during processing request: could not insert: [org.sf520.actions.user.News]
hibernate出现异常org.hibernate.exception.SQLGrammarException:could not execute
如果是在把应用部署到别的机器上,修改了数据库名称 如果在尝试了很多办法没有解决,包括修改了数据库名称,以及连接的用户名和密码 如果你的hibernate的hbm.xml文件是myeclipse自动生成的。 那么,请看看下面这个博客写的。 今天给人调试hibernate,发现一个错误,耽误了老半天; 错误提示:org.hibernate.exception.SQLGrammar
[已解决]org.hibernate.exception.SQLGrammarException: could not execute statement
第一次写问题记录,在网上找了许久但还没解决 下面是各个文件的代码: <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <!-- 1配置类和表对应
错误:org.hibernate.exception.SQLGrammarException: could not execute
于Hibernate的应用程序的开发过程中,通过Hibernate操作数据库时,在程序执行过程中出现了SQL Grammer Exception,Could not execute JDBC batch update的提示信息。遇到此类问题确实让人感觉摸不着头脑(尤其是第一次遇到),不过解决此类问题并不需要大动干戈地大规模修改代码,也不需要做更改数据库连接方式这样动用牛刀的事。问题的来源还在于细节