How to generate model from database

12,580

Solution 1

The Hibernate Tools project (available as an Eclipse plug-in, as well as an Ant task) allows for "reverse-engineering" of database schemas into appropriate entity classes.

This project is also available in the JBoss Tools project.

The facility allows for reverse-engineering of the database metadata into a Hibernate configuration file. All artifacts (including the .java files) are generated from this config file.

You can control the nature of the reverse engineering process to suit your database structure. In other words, you can specify the schemas that you wish to have the tool reverse-engineer. You could also override the JDBC type mapping, apart from limiting the reverse-engineering process to a selected set of tables.

Obligatory link:

Solution 2

Telosys does exactly this job

Let's have a look : http://www.telosys.org/

Solution 3

Minuteproject 4 JPA2 (http://minuteproject.wikispaces.com/JPA2) track does this task. Minuteproject can be run from console or command line.

You can have a quick result by generating from the console where generate a maven project containing the JPA2 mapping classes in java or groovy. If you use the command line then you need to fill an xml file that can contain additional customisation of your generated code such as packaging, enum, aliasing etc...

You can also try other track built on top JPA2 such as DAO with spring or EJB; REST; front end with Primefaces or Openxava; etc...

Share:
12,580
Admin
Author by

Admin

Updated on June 05, 2022

Comments

  • Admin
    Admin almost 2 years

    I have an existing database. I need to generate the model classes in Java from it. Are there any tool/library that will allow me to do this. It will be of great help if it can emulate the entity relationships in the database into the model classes as well.

    It is acceptable if the tool/library works with only one database vendor. I will create a database there and then generate the model.

    Thanks in advance.

    EDIT : I will probably use Hibernate as the ORM framework if I manage to generate the model.

  • user637338
    user637338 about 4 years
    Broken Link: Reverse engineering and code generation