问题
I would like to create grails domain classes from an existing database, normally i was creating database from domain classes now i need to create it from an existing database schema. Please help me if there is any command available for that.
回答1:
I'm on the same problem and I've found this Grails plugin: http://grails-plugins.github.com/grails-db-reverse-engineer/docs/manual/guide/single.html. It works perfectly: it inspects the existent database and creates domain classes, all ready to go. Just follow the steps showed in the example and you're done.
回答2:
There is a tool called GRAG: http://grag.sourceforge.net
Perhaps this might help.
回答3:
- add plugin (runtime ':db-reverse-engineer:3.0.0') in buildconfig.groovy
- Change Hibernate version from hibernate4:4.3.6.1 to hibernate:3.6.10.18
- Define package config in config.groovy to generate domain class grails.plugin.reveng.packageName="com.app.promotion"
- List the tables, you want to generate domain classes in config.groovy grails.plugin.reveng.includeTables=["promotion","event","promotionexecutionstrategy"]
- Define the shcema config in config.groovy grails.plugin.reveng.defaultSchema=”t0006”
- Then execute the command “grails -Dgrails.env=development db-reverse-engineer”. Here development is the environment in the datasource.
- After complete these steps we can see the domain classes in the package as we defined list items.
来源:https://stackoverflow.com/questions/5454897/grails-domain-class-creation-from-database