[英]Hibernate/HSQLDB: User lacks priviledges to create constraints
I am using HSQL
along with DBUnit
to run my unit tests. 我将
HSQL
和DBUnit
一起使用来运行单元测试。 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.