Reputation: 2789
I am using hibernate in my servlet to access the database.DB contains lot of foreign keys, composite keys and backward references..
Can you suggest me some tools to do reverse engineer the MySQL DB to Object oriented file in java so that I can use it with hibernate.
Upvotes: 0
Views: 4292
Reputation: 6939
IDEs usually provide such generating of entities. For example, if you use Netbeans, just go File/New/Persistence/Entity Classes from Database within a Java SE/Java EE-Project to generate JPA entities. By the way, it's a good idea to use standard JPA(2) mechanisms where possible, in order to not being dependant on a specific O/R-Mapper (such as Hibernate) or database.
Upvotes: 2
Reputation: 365
I agree with Cris,
The version 0.5.5 of Minuteproject 4 JPA2 generates also for composite key a class annotated with @Embeddable. The entity class has the @EmbeddedId as entity with the reference to the Embeddable class. For the foreign keys part of the composite key, it generates the associated @MapsId.
Meanwhile the JPA2 templates do not cover yet the composite foreign key pattern.
Hope it helped.
Upvotes: 2
Reputation: 708
We use Hibernate Tools to generate *.hbm.xml
files with the help of a hibernate.reveng.xml
file. And then, we apply Hibernate Synchronizer plugin of Eclipse to generate Entities and DAOs using *.hbm.xml
files.
hibernate.reveng.xml
fill the parts where auto generation cannot guess what you have in your mind.
Hibernate Synchronizer has the main advantage of creating base classes for your generated entities/daos. You add your custom properties/methods to subclasses (again automatically generated) of the base classes. The advantage here, is if you make changes to your database and regenerate, the changes you make (to subclasses) rest untouched.
Whatever tool you choose pay attention to build a system where code generation is easy and painless, not only for the first time but also during advanced phases of the project. If not you'll lose all the advantages.
Upvotes: 1
Reputation: 5007
The best one is MinuteProject in my opinion !
Check it on :
http://javacodesamples.wordpress.com/2011/02/04/jpa2-reverse-engineering-tool/
http://www.dzone.com/links/jpa2_reverseengineering_with_minuteproject_pragma.html
http://javacodesamples.wordpress.com/2010/09/04/minute-project-episode-1-the-productivity-provider/
It has also a Spring + Hibernate track beside the JPA so you can used that for you hibernate needs.
Upvotes: 1
Reputation: 6204
Have a look at JBoss Hibernate Tools which allows you to reverse engineer existing databases.
Upvotes: 1