0

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.

1

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I believe I should go with hibernate as far as I can. I don't want to create unnecessary dependencies with any certain database. How would I create the schema with hibernate?
Check out the Hibernate Toolset Guide - docs.jboss.org/hibernate/orm/3.3/reference/en/html/….

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.