开发者

Hibernate tool to create basic mappings based on a mysql db

Are there any tools that can look at a database, and generate the basic mapping files?

It would be great if it could take a database, and create the actual model (java classes) with a开发者_StackOverflow中文版nnotations, but not sure if that exists?


Hibernate 3 has a toolset called Hibernate Tools that provides an Eclipse plugin and an Ant task that both support Reverse Engineering:

Reverse Engineering: The most powerful feature of Hibernate Tools is a database reverse engineering tool that can generate domain model classes and Hibernate mapping files, annotated EJB3 entity beans, HTML documentation or even an entire JBoss Seam application in seconds!

...

Ant task: The Hibernate3 tools include a unified Ant task that allows you to run schema generation, mapping generation, or Java code generation as part of your build.

For the Eclipse plugin, have a look at this section of the documentation. For the Ant task, have a look at the section about reverse engineering and optionally how to control it.

Note that other IDEs also provide support for reverse engineering (see Hibernate Reverse Engineering for Netbeans 6.5 and Generating Persistence Mappings from Database Schema for IntelliJ).


I just happened to stumble across this problem and I think I have found a perfect tool for the job.

http://hibernatepojoge.sourceforge.net/


Features : (in case you are lazy to go through the provided link)

  • Java objects representing each table using annotations for use with Hibernate.
  • A JUnit test case per table that uses the objects generated to create, populate, save, retrieve and compare results
  • DAO per class
  • The appropriate enumeration files
  • Spring and hibernate configuration
  • DAO layers
  • A data factory class per schema to return a pre-populated object with random data (for boundary checking, database population, etc)

Also supports:

  • Join tables including those with additional fields in link tables
  • Polymorphism/inheritance support
  • Composite Keys
  • One-To-One, many-to-one, many-to-many, etc
  • Multiple schema support (4 modes)
  • Natural Keys
  • Enumerations (including those entries which cannot be mapped cleanly onto the java world)
  • A whole bunch of more stuff (see sample.xml)

I would also like to say that setting this up is quite straight forward; You just have to have a hibernate configuration file and the jar file downloaded from the site. Then it's just a matter executing a jar file, passing the config.xml as a parameter!


If you are using eclipse or ant...

Jboss tools


You might find what you need here, I found it on the fly: MyGeneration.

I know there are others that exist, but I don'T remember by heart. Hope this helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜