简体   繁体   English

Hibernate / HSQLDB:用户缺乏创建约束的权限

[英]Hibernate/HSQLDB: User lacks priviledges to create constraints

I am using HSQL along with DBUnit to run my unit tests. 我将HSQLDBUnit一起使用来运行单元测试。 So far, I can start HSQL from a script which creates a new schema, then Hibernate creates the tables and DBUnit add the data in these tables. 到目前为止,我可以从创建新模式的脚本启动HSQL ,然后Hibernate创建表, DBUnit在这些表中添加数据。 However, I keep having these errors logs: 但是,我一直有这些错误日志:

2013-10-10 09:38:05,559 INFO  org.hibernate.tool.hbm2ddl.SchemaExport - HHH000227: Running hbm2ddl schema export
2013-10-10 09:38:05,563 ERROR org.hibernate.tool.hbm2ddl.SchemaExport - HHH000389: Unsuccessful: alter table dbo.MY_TABLE drop constraint FK58568EF941C829A
2013-10-10 09:38:05,563 ERROR org.hibernate.tool.hbm2ddl.SchemaExport - user lacks privilege or object not found: DBO.MY_TABLE
2013-10-10 09:38:05,564 ERROR org.hibernate.tool.hbm2ddl.SchemaExport - HHH000389: Unsuccessful: alter table dbo.MY_TABLE drop constraint FK58568EF12A53C22
2013-10-10 09:38:05,564 ERROR org.hibernate.tool.hbm2ddl.SchemaExport - user lacks privilege or object not found: DBO.MY_TABLE
2013-10-10 09:38:05,592 ERROR org.hibernate.tool.hbm2ddl.SchemaExport - HHH000389: Unsuccessful: alter table dbo.MY_TABLE add constraint FK58568EF941C829A foreign key (id_my_other_table) references dbo.MY_OTHER_TABLE
2013-10-10 09:38:05,592 ERROR org.hibernate.tool.hbm2ddl.SchemaExport - The table data is read only in statement [alter table dbo.MY_TABLE add constraint FK58568EF941C829A foreign key (id_my_other_table) references dbo.MY_OTHER_TABLE]

It seems that only constraints cannot be created for some reason. 似乎由于某种原因无法创建约束。 I checked that the tables have been properly created and the data added with org.hsqldb.util.DatabaseManagerSwing . 我检查了表是否已正确创建,并使用org.hsqldb.util.DatabaseManagerSwing添加了数据。 I wanted to have a look in INFORMATION_SCHEMA.TABLE_CONSTRAINTS but the INFORMATION_SCHEMA is empty. 我想看一下INFORMATION_SCHEMA.TABLE_CONSTRAINTS但是INFORMATION_SCHEMA为空。 Could it be the reason or these errors? 可能是原因还是这些错误? Something else? 还有吗 As I'm using the user SA which has all priviledges, he should be able to create constraints? 当我使用具有所有特权的用户SA ,他应该能够创建约束吗?

Regarding my configuration: 关于我的配置:

Hibernate 4.1.10.Final Hibernate 4.1.10.Final

HSQLDB 2.3.0 HSQLDB 2.3.0

DBUnit 2.4.9 DBUnit 2.4.9

In my beans.xml I have: 在我的beans.xml我有:

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="org.hsqldb.jdbcDriver" />
        <property name="url" value="jdbc:hsqldb:file:initdata" />
        <property name="username" value="sa" />
        <property name="password" value="" />
    </bean>

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan">
        <list>
            <value>primobox.demat.model.sql</value>
        </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
                <prop key="hibernate.hbm2ddl.auto">create</prop>
                <prop key="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="javax.persistence.validation.mode">auto</prop>
                <prop key="hibernate.connection.defaultNChar">true</prop>
                <prop key="hibernate.connection.useUnicode">true</prop>
                <prop key="hibernate.connection.characterEncoding">UTF-8</prop>
                <prop key="hibernate.connection.charSet">UTF-8</prop>
            </props>
        </property>
    </bean>

My initdata.properties 我的initdata.properties

version=2.0.0
modified=yes
files_readonly=true

One likely cause is Hibernate sees a different, empty database that has no tables. 一个可能的原因是Hibernate看到另一个没有表的空数据库。

The line below connects to a relative path. 下面的线连接到相对路径。 Change it to an absolute path here and anywhere else you connect to the database and it should work. 在此处以及您连接到数据库的其他任何地方将其更改为绝对路径,它应该可以工作。

<property name="url" value="jdbc:hsqldb:file:initdata" />

The other problem is you have set up files_readonly in the .properties file. 另一个问题是您已在.properties文件中设置files_readonly。 Do not create a properties file and let the engine create the database when you first connect. 首次连接时,请勿创建属性文件,而应让引擎创建数据库。 Delete any existing database. 删除任何现有数据库。

对我来说,使用此行解决了问题:

sessionFactory.getHibernateProperties().put("hibernate.hbm2ddl.auto", "create");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:用户缺少未找到HSQLDB的权限或对象 - ERROR: User lacks privilege or object not found HSQLDB HSQLDB:用户缺少特权或找不到对象:USERS - HSQLDB : user lacks privilege or object not found: USERS SpringBoot 用户缺少权限或未找到 object HSQLDB - SpringBoot user lacks privilege or object not found HSQLDB 带有 HSQLDB 的 Spring 数据 JPA:用户缺少权限或找不到对象 - Spring data JPA with HSQLDB: user lacks privilege or object not found 带有Postgresql的HSQLDB:找不到类型或用户缺少特权:BIGSERIAL - HSQLDB with Postgresql: type not found or user lacks privilege: BIGSERIAL HSQLDB ORACLE用户缺少特权或找不到对象:REGEXP_LIKE - HSQLDB ORACLE user lacks privilege or object not found: REGEXP_LIKE HSQLDB:java.sql.SQLSyntaxErrorException:user缺少未找到的权限或对象 - HSQLDB: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found org.hsqldb.HsqlException:用户缺少特权或找不到对象:USER0_.NAME - org.hsqldb.HsqlException: user lacks privilege or object not found: USER0_.NAME Java HQL org.hsqldb.HsqlException:user缺少未找到的权限或对象 - Java HQL org.hsqldb.HsqlException: user lacks privilege or object not found 需要访问 hsqldb static 方法但获取 java.sql.SQLSyntaxErrorException: user缺少4B6668CFFDEnot89131CBD - need to access hsqldb static method but get java.sql.SQLSyntaxErrorException: user lacks privilege or object not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM