I am using HSQL
along with DBUnit
to run my unit tests. 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. 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
. I wanted to have a look in INFORMATION_SCHEMA.TABLE_CONSTRAINTS
but the INFORMATION_SCHEMA
is empty. 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?
Regarding my configuration:
Hibernate
4.1.10.Final
HSQLDB
2.3.0
DBUnit
2.4.9
In my beans.xml
I have:
<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
version=2.0.0
modified=yes
files_readonly=true
One likely cause is Hibernate sees a different, empty database that has no tables.
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. Do not create a properties file and let the engine create the database when you first connect. Delete any existing database.