dbmapper


Map your database tables to JPA and JAXB objects

Point this tool at your database to map from your relations to JPA and JAXB classes. However, it is designed specifically to work well with databases where a certain number of best practices are adhered to:

  • Every table should have a primary key named 'id' that auto-increments on insert
  • Foreign key columns must be named tablename_id
  • Many to Many join tables must be named tablename1_tablename2
  • All foreign keys should be declared in the database

If you can live by these rules you will never have to write JPA classes again. Here is the usage message:

Usage: com.moonspider.dbmap.GenerateConfig -type (-t) [String] The type to generate, either 'jpa' or 'gorm' (experimental) (jpa) -destinationDirectory (-d) [String] Destination directory -url [String] The url of the database -pkg (-package) [String] The target package () -user (-u) [String] Database user (sa) -password (-p) [String] Database password () -globalExtends (-extends) [String] Class for all Java classes to extend -globalImplements (-implements) [String] Class for all Java classes to implement -driver [String] Database drive class -extension (-ext) [String] File extension for the generated code (java) -hibernate [String] Generate hibernate.cfg.xml to this directory -jaxb [flag] Enable xml binding generation -schema [String] Specify the non-default schema to use

The Grails GORM support is very experimental and doesn't work well for complex relationships yet. The JPA support is very solid and has been used in commercial products. There are lots of things that you can override using a special XML configuration file that will allow you to break some of the rules above, but I don't recommend it, you can find an example in the tests.

Project Information

Labels:
java jpa jaxb database hibernate grails