Traditionally when I am designing a project I will usually start with developing a relational data model. If I’m using Hibernate, I will proceed to generate or write my Hibernate mapping files (.hbm) and from there I can generate the plain Java objects (POJO’s). I decided to try the approach the other way around. Using MyEclipse’s UML modeling, I created my domain model. Besides modeling the data in UML up front, it let’s me ignore the details of the physicial data implementation at a stage when I think those details are distracting. Also when starting in UML it seems much easier for me to discover the service-type classes and collaborators with the domain model.
Now for getting to the DDL.
- The POJO’s have to be annotated by hand. This could maybe be automated in the generation of the Java code from the UML but the MyEclipse interface doesn’t allow for this. It would be a nice touch though. Understanding how to represent relationships in XDoclet for Hibernate is critical.
- Run XDoclet to generate the .hbm files. Again I used the stock plugin with MyEclipse to run XDoclet.
- The last step really is to call upon Hibernate to generate the DDL at startup time. Here’s were I think a rigorous set of JUnit tests works well for verifying that the data model is correct and matches syntactically what the business layer expects.
One final aspect I’m yet to work out is how to introduce static data into the build process. For lack of anything mor elegant, I’m using a custom Ant task to run a MySQL script for the data import when my application gets deployed.