Reverse engineer your database structure into java JPA classes. The g9 Database Import Eclipse plugin supports converting database schemas to an Ecore or Xcore model, or Java source code.
The domain model based on the imported schema will contain classes, groups and associations. Database tables results in domain model classes, and the columns of a table will become attributes in the class. Foreign keys in the database schema are treated as associations. Groups or value objects are created from indexes, primary keys and foreign keys in the database schema containing more than one column.
A database schema will be imported to an existing project in an Eclipse workspace. Start by creating a project of the right type into which your database schema will be imported:
- If the target is Java, create a Java project
- If the target is Xcore, create an Xcore project
- Other projects will produce Ecore models
The imported database schema can also be used as a domain model in a g9 modeling project. The latter requires a full g9 installation. See g9 products.
Getting started with Database Import
Open the Import wizard by selecting the target project and the Import… context menu of the existing project. Expand the g9 category, select Import Database Model and click the [Next] button.
On the wizard page Database Model Import - Connection, choose one of the built-in JDBC drivers (MySQL, MS SQL Server, Sybase ASE or Derby) for your database, or register a JDBC driver suitable for your database type by pressing the [Maintain JDBC Drivers] button. Fill in the connection properties to access the database to be imported:
Click the [Fetch] button to import the schema from the database. Attributes with the name of the ancestor and locking columns will be excluded by matching the names used in the database before fetching the schema.
After a successful fetch of the database schema, page Database Model Import - Create Model shows the tables referenced in the schema. Every time the database schema has changed, click the Fetch button to update the database model in the wizard.
In the section Import to a Java Model or Import to an Xcore Model, parameters can be set in order to customize the imported model. Common parameters for all model types are:
- Model or Source folder: This is the folder in your project where the imported model files will be saved. If you have chosen an Ecore or Xcore model, the imported models files are stored here. For Java code models, this folder is the source directory in the Java project.
- Root package: This is a common root package for imported domain model elements.
- Generate value objects: If checked, the import will attempt to create value object classes for groups found in the database schema. A group can be imported as a value object class if no other value object classes contain any of the attributes in the group or there are no bi-directional associations in the group.
For Java projects, the following parameters are available in addition to the common parameters:
- Generate JPA annotations: If checked, JPA annotations are generated to the Java classes. For more information on JPA annotations, see Modeling with Java code as Model Source in the g9 User Guide.
- Generate g9 annotations: If checked, g9 annotations are generated to the Java classes. For more information on g9 annotations, see Modeling with Java code as Model Source in the g9 User Guide.
- Use ‘is’ prefix for getters that return boolean. A getter is generated to the Java class for all attributes. If checked, the getter for boolean attributes will be named
The tables found in the database schema are shown in a list. To exclude a table from being imported to the domain model, uncheck the Include check box for that table. By selecting multiple lines in the list of tables, the inclusion and sub package of all selected tables can be edited.
To edit the package and name of a class, select a line in the list of tables and click the [Edit…] button. This opens the Table Configuration page:
In the Table Configuration page, a sub package can be added to the common root package for all classes. The suggested class name can be changed. To exclude a column from being imported to the domain model, uncheck the Include check box for that column. By selecting multiple lines in the list of columns, the checked/unchecked columns will be included/excluded from being imported to the domain model.
In the Table Configuration page, select a line in the list of columns and click the [Edit…] button. This opens the Column Configuration page where the suggested attribute name can be edited.
The last step is the mapping of JDBC types to Domain Model types. The g9 Database Import has a default mapping of all JDBC types. To change the mapping of a type, select the JDBC type in the list and click the [Edit…] button. This will open the JDBC Type Mapping Configuration page:
Click the [Finish] button to start the database model import. For each included table, a Java class will be generated to the target project:
If the Cancel button of the wizard is clicked, and any of the values in the dialog is changed, you can choose to save the values. The values are saved for the current import project, and will be restored the next time the Import Database Model wizard is started for the project.
g9 2.8.1 - juli 2018
g9 2.7.1 - september 2017
g9 2.7.0 - juni 2017
g9 2.6.0 - april 2017
g9 2.5.0 - september 2016
g9 2.4.0 - juni 2016
g9 2.3.0 - april 2016
g9 2.2.0 - februar 2016
g9 2.1.0 - oktober 2015
g9 2.0.0 - august 2015
Ta kontakt med oss dersom du ønsker eldre versjoner.