Question

I'm using Spring embedded database in my unit tests. From Spring documentantatio:

<jdbc:embedded-database id="dataSource">
    <jdbc:script location="classpath:schema.sql"/>
    <jdbc:script location="classpath:test-data.sql"/>
</jdbc:embedded-database>

There are many examples all over the web which basically tell the same tale. I am able to manually create the sql statements from the production database. I could use mysqldump for example (assuming the SQL produced is accepted by HSQL). But my tables are already defined in .hbm.xml files. Is there a way to generate them automatically into the .sql files?

The purpose of all this is naturally to initialize the database. My immediate intent is to only setup the tables; I'll insert the necessary test data in the unit tests themselves.

Was it helpful?

Solution

You could let Hibernate generate your schema from the mapping file(s). You wouldn't then need to have a script do it for your integration tests. Check out the Hibernate Toolset Guide for how to do this.

Alternatively you could Retag this question for the database you are working with and see the best way of creating a schema generation script.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top