How to populate web application with initial data
@David, thanks for your post. The only reasonable solution I've find to seed initial data is similar to yours - that is inserting data in tests. In my code I even don't use hibernate3-maven-plugin. Database creation in done by Spring in file jpaContext.xml
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="jpaVendorAdapter">
<bean
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="generateDdl" value="true" />
<property name="databasePlatform" value="org.hibernate.dialect.HSQLDialect"/>
</bean>
</property>
<property name="dataSource" ref="dataSource"/>
As I wrote I use org.springframework.test.jpa.AbstractJpaTests with overriden method
@Override
protected String[] getConfigLocations() {
return new String[]{
"classpath:/jpaContext.xml"};
}
I think it shold simplify your solution. I still search for a better resolution for creating initial data. Creating objects with a lot of relations by hand is cumbersome.
EDIT: Added a link to a blog post showing how to test Hibernate JPA with Spring and DbUnit.
[...] I'd like to have a maven build which create database from entities
There is a maven hibernate3 plugin with an hibernate3:hbm2ddl goal that might help. Coupled with the maven sql plugin, it should be possible to create this schema from the generated DDL.
[...] then populates initial/dictionary data
Again, the maven sql plugin could do the job here. Or maybe with DBUnit which is another elegant solution (see the maven dbunit plugin).
and run unit and integration tests.
Well, I'm not sure your unit tests should access the database but, for integrations tests, check DBUnit as I said. It's really a very nice tool that allows you to setup up the database in a known state, test tables for expected content after a test execution and put the database back in the initial state. See Testing JPA Hibernate with Spring & DbUnit for a nice example.
This process should be fully automated to put this build in CI server (hudson), crating new database from scratch is also appreciate.
I think this is feasible.