문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top