1

我有基于 Spring-MVC 的 Web 应用程序。我已经将它与 Hibernate 3.6.0 集成。当我尝试保存名为 User 的实体时,我得到:

org.hsqldb.HsqlException:用户缺少权限或找不到对象:USER

我发现数据库中没有表 USER 但为什么呢?我的 springs ServletDispatcher 的配置文件片段:

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="org.hsqldb.jdbcDriver"></property>
        <property name="url" value="jdbc:hsqldb:file: db/autostop; shutdown=true"></property>
        <property name="username" value="SA"></property>
        <property name="password" value=""></property>
    </bean>
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="packagesToScan" value="prv.bladositto.autostop.persistance.hibernate.model"/>
        <property name="hibernateProperties">
            <props>
                <prop key="dialect">org.hibernate.dialect.HSQLDialect</prop>
                <prop key="show_sql">true</prop>
                <prop key="hbm2ddl.auto">create-drop</prop>
            </props>
        </property>
    </bean>

根异常堆栈跟踪:

org.hsqldb.HsqlException: user lacks privilege or object not found: USER
    org.hsqldb.error.Error.error(Unknown Source)
    org.hsqldb.error.Error.error(Unknown Source)
    org.hsqldb.SchemaManager.getTable(Unknown Source)
    org.hsqldb.ParserDQL.readTableName(Unknown Source)
    org.hsqldb.ParserDQL.readSimpleRangeVariable(Unknown Source)
    org.hsqldb.ParserDML.compileInsertStatement(Unknown Source)
    org.hsqldb.ParserCommand.compilePart(Unknown Source)
    org.hsqldb.ParserCommand.compileStatement(Unknown Source)
    org.hsqldb.Session.compileStatement(Unknown Source)
    org.hsqldb.StatementManager.compile(Unknown Source)
    org.hsqldb.Session.execute(Unknown Source)
    org.hsqldb.jdbc.JDBCPreparedStatement.<init>(Unknown Source)
    org.hsqldb.jdbc.JDBCConnection.prepareStatement(Unknown Source)
    org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:524)
    org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:116)
    org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.prepare(IdentityGenerator.java:90)
    org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:54)
    org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2327)
    org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2834)
    org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71)
    org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
    org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:320)
    org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:203)
    org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:129)
    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:713)
    org.hibernate.impl.SessionImpl.save(SessionImpl.java:701)
    org.hibernate.impl.SessionImpl.save(SessionImpl.java:697)
    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)
    prv.bladositto.autostop.persistance.hibernate.UserServiceImpl.save(UserServiceImpl.java:23)
    prv.bladositto.autostop.controllers.UsersController.createUser(UsersController.java:40)
    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:601)
    org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
    org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
    org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
    org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
    org.springframework.web.servlet.FrameworkServlet.doPut(FrameworkServlet.java:800)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:757)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:74)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

编辑

我正在将我的应用程序部署到 JBoss AS 7。它位于 Ubuntu 上的 /usr/share/JBoss..7/ 上。也许这很重要。

4

2 回答 2

0

USER 是一个特殊的函数名称,不应用于您的实体。

于 2012-08-22T13:55:29.473 回答
0

我解决了这个问题。Hibernate 中的属性应以“hibernate.”为前缀。以下更改成功了:

<property name="hibernateProperties">
  <props>
     <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
     <prop key="hibernate.show_sql">true</prop>
     <prop key="hibernate.hbm2ddl.auto">create-drop</prop>
  </props>
</property>
于 2012-08-26T16:23:10.090 回答