Writting some integration tests in Spring (Like in this question) I will like to avoid the work of a big script to create all tables in HSQL:
<jdbc:script location="classpath:createSchema.sql" />
As Spring is creating and updating my development tables from the model automagically. How could I tell Spring to do the same things for my integration tests?
My datasource file is
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns= "http://www.springframework.org/schema/beans"
xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
xmlns:context= "http://www.springframework.org/schema/context"
xmlns:jee= "http://www.springframework.org/schema/jee"
xmlns:p= "http://www.springframework.org/schema/p"
xmlns:jdbc= "http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd">
<!-- Usamos HSQLDB para hacer las pruebas con in-memory db -->
<jdbc:embedded-database id="dataSource" type="HSQL">
<jdbc:script location="classpath:create_schema.sql"/>
<jdbc:script location="classpath:import.sql"/>
</jdbc:embedded-database>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.myProject.model" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.default_schema">TESTING</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">create-drop</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>
Update: After NimChimpsky answer I had included the schema name in hibernate properties and created a script with just:
CREATE SCHEMA TESTING
After trying the first insert int the import.sql script I see: org.hsqldb.hsqlexception user lacks privilege or object not found [MyTable]