In many enterprise environments, applications will be based on an existing database schema, not the other way around. Hibernate, in conjunction with a tool called Middlegen, supports this development model. In this chapter, persistent objects will be derived from an existing MySQL schema, using Middlegen to generate the Hibernate mapping files; these will in turn be used to generate Java source files.
The example in this chapter should be familiar to anyone who has ever at tended school. The database schema models a set of courses and students, tracking exams and exam results for each student. Many books on relational database design include this example—especially some of the more academic texts.