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.

denarced
  • 322
  • 3
  • 10
  • You may modify code from my answer about JPA: http://stackoverflow.com/questions/6856934/how-to-generate-schema-for-jpa-entity/6883384#6883384 – Slava Semushin Sep 02 '12 at 19:34

1 Answers1

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.

Rich Cowin
  • 668
  • 1
  • 8
  • 17
  • 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? – denarced Sep 02 '12 at 17:54
  • Check out the Hibernate Toolset Guide - http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/toolsetguide.html. – Rich Cowin Sep 03 '12 at 06:11