Initial SchemaIn this scenario, development is based on an existing schema. Application designers are often not allowed to significantly update or change a schema, perhaps because it is in use by other applications, or because the database is a legacy system, or for any number of other possible reasons. The point is that the database design in this scenario drives the application development. A schema is given, and may occasionally be embroidered (for example, adding a column), but the overall structure is fixed prior to application development. Listing 4.1 shows the script used to generate the schema for the database in this chapter. Note that this script is written to automatically drop and recreate the tables used in the chapter each time it is run, destroying any data present in the tables (obviously this would not be used in a "real" system). The schema in this example includes several MySQL specific commands. For example, the TYPE=InnoDB command tells MySQL to convert the tables to the InnoDB format, a more modern format for storing database data than the default MySQL format. Similarly, the foreign-key checks are disabled to avoid errors when dropping the tables. The schema described in this chapter is based on MySQL 4.0.18. Depending on the database you are using, you may need to modify this schema script to be able to execute it. Alternatively, you may wish to use the graphical administrative tool included with your database (if any) to create this schema.
Pay close attention to the commands to create indexes and foreign key constraints at the end of the script. Middlegen (the tool used later in this chapter) reads these constraints and uses them to generate relationship mappings. In other words, Middlegen reads these key relationships and uses them to establish relationships in the generated Hibernate mapping files (and from there in the generated Java source). If you wish to see a graphical representation of the tables generated by this script, you may wish to skip ahead to glance at the tables in Figure 4.2. Listing 4.1. Schema Generation Script[View full width]
Figure 4.2. Middlegen Graphical Interface[View full size image] |
Monday, December 21, 2009
Initial Schema
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment