hsql错误: user lacks privilege or object not found: LAST_INSERT_ID

阅读更多
1.1.1、问题现象
环境:windows vista+JDK1.6+Apusic7.0+cfconsole+hsqldb2.2.6



从hsqldb中查询数据时报错,提示用户权限缺失或者对象不存在。

1.1.2、日志情况
错误日志如下:

org.springframework.dao.InvalidDataAccessResourceUsageException: could not retrieve generated id after insert: [com.wondersgroup.framework.security.bo.UserLoginHistory]; nested exception is org.hibernate.exception.SQLGrammarException: could not retrieve generated id after insert: [com.wondersgroup.framework.security.bo.UserLoginHistory]

       at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:630)

       at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)

       at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424)

       at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)

       at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:748)

       at com.wondersgroup.framework.core.dao.impl.AbstractHibernateDAOImpl.save(AbstractHibernateDAOImpl.java:131)

       at com.wondersgroup.framework.security.service.impl.UserServiceImpl.addUserLoginHistory(UserServiceImpl.java:922)

       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

       at java.lang.reflect.Method.invoke(Method.java:597)

       at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)

       at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)

       at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)

       at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)

       at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)

       at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)

       at $Proxy24.addUserLoginHistory(Unknown Source)

       at com.wondersgroup.framework.common.web.login.action.LoginAction.recordUserLogin(LoginAction.java:127)

       at com.wondersgroup.framework.common.web.login.action.LoginAction.operate(LoginAction.java:297)

       at com.wondersgroup.framework.core.web.struts2.action.BaseAction.execute(BaseAction.java:42)

       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

       at java.lang.reflect.Method.invoke(Method.java:597)

       at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:404)

       at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267)

       at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:229)

       at com.wondersgroup.framework.core.web.struts2.interceptor.AjaxExceptionMappingInterceptor.intercept(AjaxExceptionMappingInterceptor.java:44)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

       at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

       at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

       at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221)

       at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

       at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

       at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

       at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:150)

       at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:48)

       at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

       at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

       at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

       at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:184)

       at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

       at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

       at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

       at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:105)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

       at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

       at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

       at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:83)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

       at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

       at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

       at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:207)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

       at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

       at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

       at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:74)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

       at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

       at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

       at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:127)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

       at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

       at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

       at org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:107)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

       at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

       at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

       at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:206)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

       at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

       at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

       at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:115)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

       at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

       at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

       at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:143)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

       at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

       at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

       at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:121)

       at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

       at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

       at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

       at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:170)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

       at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

       at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

       at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:123)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

       at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

       at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

       at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)

       at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)

       at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)

       at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

       at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:50)

       at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:504)

       at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:422)

       at com.apusic.web.container.FilterComponent.doFilter(Unknown Source)

       at com.apusic.web.container.FilterChainImpl.performFilter(Unknown Source)

       at com.apusic.web.container.FilterChainImpl.doFilter(Unknown Source)

       at com.wondersgroup.framework.common.web.filter.CommonWebFilter.doFilter(CommonWebFilter.java:56)

       at com.apusic.web.container.FilterComponent.doFilter(Unknown Source)

       at com.apusic.web.container.FilterChainImpl.performFilter(Unknown Source)

       at com.apusic.web.container.FilterChainImpl.doFilter(Unknown Source)

       at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)

       at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

       at com.apusic.web.container.FilterComponent.doFilter(Unknown Source)

       at com.apusic.web.container.FilterChainImpl.performFilter(Unknown Source)

       at com.apusic.web.container.WebContainer.invoke(Unknown Source)

       at com.apusic.web.container.WebContainer.processRequest(Unknown Source)

       at com.apusic.web.http.VirtualHost.processRequest(Unknown Source)

       at com.apusic.web.http.HttpServer.processRequest(Unknown Source)

       at com.apusic.web.http.HttpConnectionHandler.service(Unknown Source)

       at com.apusic.web.http.ConnectionHandler.processRequest(Unknown Source)

       at com.apusic.web.http.ConnectionHandler.processConnection(Unknown Source)

       at com.apusic.web.http.ConnectionHandler.run(Unknown Source)

       at com.apusic.util.ThreadPoolImpl$WorkerThread.run(Unknown Source)

Caused by: org.hibernate.exception.SQLGrammarException: could not retrieve generated id after insert: [com.wondersgroup.framework.security.bo.UserLoginHistory]

       at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)

       at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)

       at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:93)

       at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2186)

       at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2666)

       at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71)

       at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)

       at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:321)

       at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)

       at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)

       at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)

       at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)

       at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:117)

       at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)

       at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:534)

       at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:526)

       at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:522)

       at org.springframework.orm.hibernate3.HibernateTemplate$16.doInHibernate(HibernateTemplate.java:751)

       at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)

       ... 138 more

Caused by: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: LAST_INSERT_ID

       at org.hsqldb.jdbc.Util.sqlException(Unknown Source)

       at org.hsqldb.jdbc.Util.sqlException(Unknown Source)

       at org.hsqldb.jdbc.JDBCPreparedStatement.(Unknown Source)

       at org.hsqldb.jdbc.JDBCConnection.prepareStatement(Unknown Source)

       at com.apusic.jdbc.adapter.ConnectionHandle.prepareStatement(Unknown Source)

       at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:534)

       at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:116)

       at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:109)

       at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:76)

       ... 154 more

1.1.3、问题分析
从错误日志的提示,可以看出根本原因是:Caused by: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: LAST_INSERT_ID,考虑数据库中此列是否存在,经查阅资料发现,导致数据库中列丢失的原因是,通过hsqldb管理创建完sql脚本,没有正常关闭数据导致的。





1.1.4、解决方案
通过hsqldb的管理器执行完sql脚本后,要执行【shutdown】命令来关闭数据库,而不要采用[Ctrl]+[C]的方式,否则会造成数据错误,提示找不到对象或者权限缺失:Caused by: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: LAST_INSERT_ID。

你可能感兴趣的:(java,hsql)