preface

When the author develops springboot project, the persistence layer is supported by JPA, and a large number of entity classes need to be created. Of course, on the market, such as IDEA flagship edition has provided entity generation tools, but it is a paid version. If it is too heavy to use this function alone, And the Internet searched for a round but did not find a more suitable and easy to use visual entity generator JPAEntityGenerator, so I spent several days to write such a tool, support Java and Kotlin language entity generation, and because it is based on Swing development, Therefore, it supports Windows, MacOS and Linux platforms. Currently, version 1.0 only supports mysql data sources.

Tool download address

Github.com/aladdin0414…

Tools to run

To install JRE1.8 or later, download the ZIP package, decompress it, go to the bin directory, and double-click jPaEntityGenerator. bat on Windows. In Linux or MacOS, run JPAEntityGenerator.

Tool is introduced

Data Source Configuration

Multiple data sources are supported. Click File->New to create a New data source

Enter database connection Required fields include:

  1. Connection name: indicates the Connection name
  2. Hostname: IP address and port number, separated by colons. If the database port number is 3306, this parameter is optional.
  3. Password: indicates the database Password

When complete, click the Connect button and save the data source configuration if the connection is successful.

The entity to generate

  • After the database is configured and connected successfully, all databases to be selected are displayed in the schema. After the database is selected, a list of all data tables is displayed below.
  • Select the entity language you want to export, Java or Kotlin
  • Enter the Packagename stored in the project. You need to manually change it later
  • Enter the directory for exporting physical files. Currently, enter the directory manually
  • Select the data table to export. You can select one or more data tables
  • Perform the export operation in the corresponding folder<folder>/<schema>/<connectionname>/<language>You can see the generated entity class

Examples of generated Java entity code:

package com.aladdin0414.test.domain;
import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Objects;

/**
 * Generated by JPAEntityGenerator
 * @date2021/06/10 17:51:13 * * /
@Entity
@Table(name = "columns_priv", schema = "mysql", catalog = "")
public class ColumnsPriv {
	private String host;
	private String db;
	private String user;
	private String tableName;
	private String columnName;
	private Timestamp timestamp;
	private String columnPriv;

	@Basic
	@Column(name = "Host")
	public String getHost(a) {
		return host;
	}

	public void setHost(String host) {
		this.host = host;
	}

	@Basic
	@Column(name = "Db")
	public String getDb(a) {
		return db;
	}

	public void setDb(String db) {
		this.db = db;
	}

	@Id
	@Column(name = "User")
	public String getUser(a) {
		return user;
	}

	public void setUser(String user) {
		this.user = user;
	}

	@Basic
	@Column(name = "Table_name")
	public String getTableName(a) {
		return tableName;
	}

	public void setTableName(String tableName) {
		this.tableName = tableName;
	}

	@Basic
	@Column(name = "Column_name")
	public String getColumnName(a) {
		return columnName;
	}

	public void setColumnName(String columnName) {
		this.columnName = columnName;
	}

	@Basic
	@Column(name = "Timestamp")
	public Timestamp getTimestamp(a) {
		return timestamp;
	}

	public void setTimestamp(Timestamp timestamp) {
		this.timestamp = timestamp;
	}

	@Basic
	@Column(name = "Column_priv")
	public String getColumnPriv(a) {
		return columnPriv;
	}

	public void setColumnPriv(String columnPriv) {
		this.columnPriv = columnPriv;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null|| getClass() ! = o.getClass())return false;
		ColumnsPriv columnsPriv = (ColumnsPriv) o;
		return Objects.equals(host, columnsPriv.host) && Objects.equals(db, columnsPriv.db) && Objects.equals(user, columnsPriv.user) && Objects.equals(tableName, columnsPriv.tableName) && Objects.equals(columnName, columnsPriv.columnName) && Objects.equals(timestamp, columnsPriv.timestamp) && Objects.equals(columnPriv, columnsPriv.columnPriv);
	}

	@Override
	public int hashCode(a) {
		returnObjects.hash(host, db, user, tableName, columnName, timestamp, columnPriv); }}Copy the code

Examples of kotlin code:

package com.aladdin0414.test.domain;

import java.sql.Timestamp
import java.util.*
import javax.persistence.*

/**
 * Generated by JPAEntityGenerator
 * @date2021/06/10 17:51:18 * /
@Entity
@Table(name = "columns_priv", schema = "mysql", catalog = "")
class ColumnsPriv {

	@Column(name = "Host")
	@Basic
	var host: String? = null

	@Column(name = "Db")
	@Basic
	var db: String? = null

	@Column(name = "User")
	@Id
	var user: String? = null

	@Column(name = "Table_name")
	@Basic
	var tableName: String? = null

	@Column(name = "Column_name")
	@Basic
	var columnName: String? = null

	@Column(name = "Timestamp")
	@Basic
	var timestamp: Timestamp? = null

	@Column(name = "Column_priv")
	@Basic
	var columnPriv: String? = null

	override fun equals(o: Any?).: Boolean {
		if (this === o) return true
		if (o == null|| javaClass ! = o.javaClass)return false
		val columnsPriv = o as ColumnsPriv
		return host == columnsPriv.host && db == columnsPriv.db && user == columnsPriv.user && tableName == columnsPriv.tableName && columnName == columnsPriv.columnName && timestamp == columnsPriv.timestamp && columnPriv == columnsPriv.columnPriv
	}

	override fun hashCode(a): Int {
		return Objects.hash(host, db, user, tableName, columnName, timestamp, columnPriv)
	}
}
Copy the code

Open source address

The project is currently open source on Github, written in Kotlin language, if you are interested in it, please check it out

Github.com/aladdin0414…