I use GORM to generate my database's DDL from groovy classes. Which is great. However, the order of fields in the generated SQL is not the same as the order of fields in the class. For example, if I create the class
class Person
{
String firstName
String lastName
String address
String email
}
the following SQL is generated (for MySQL)
CREATE TABLE `test` (
`id` bigint(20) NOT NULL auto_increment,
`version` bigint(20) NOT NULL,
`address` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`first_name` varchar(255) NOT NULL,
`last_name` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
The fields have been sorted into alphabetical order (after the autogenerated id and version fields). This is O.K. in this instance, but I have some much wider tables in which there is important contextual information in the order of the fields.
Here is my question: How do you tell GORM to order the fields in SQL in the order of declaration in the groovy class?