JPA Entity Generator

Lombok-wired JPA entity source code generator, Gradle and Maven supported.

License

License

GroupId

GroupId

com.smartnews
ArtifactId

ArtifactId

jpa-entity-generator
Last Version

Last Version

0.99.8
Release Date

Release Date

Type

Type

jar
Description

Description

JPA Entity Generator
Lombok-wired JPA entity source code generator, Gradle and Maven supported.
Project URL

Project URL

https://github.com/smartnews/jpa-entity-generator
Source Code Management

Source Code Management

https://github.com/smartnews/jpa-entity-generator

Download jpa-entity-generator

How to add to project

<!-- https://jarcasting.com/artifacts/com.smartnews/jpa-entity-generator/ -->
<dependency>
    <groupId>com.smartnews</groupId>
    <artifactId>jpa-entity-generator</artifactId>
    <version>0.99.8</version>
</dependency>
// https://jarcasting.com/artifacts/com.smartnews/jpa-entity-generator/
implementation 'com.smartnews:jpa-entity-generator:0.99.8'
// https://jarcasting.com/artifacts/com.smartnews/jpa-entity-generator/
implementation ("com.smartnews:jpa-entity-generator:0.99.8")
'com.smartnews:jpa-entity-generator:jar:0.99.8'
<dependency org="com.smartnews" name="jpa-entity-generator" rev="0.99.8">
  <artifact name="jpa-entity-generator" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.smartnews', module='jpa-entity-generator', version='0.99.8')
)
libraryDependencies += "com.smartnews" % "jpa-entity-generator" % "0.99.8"
[com.smartnews/jpa-entity-generator "0.99.8"]

Dependencies

compile (5)

Group / Artifact Type Version
com.google.guava : guava jar 26.0-jre
org.apache.commons : commons-lang3 jar 3.8.1
org.freemarker : freemarker jar 2.3.28
org.yaml : snakeyaml jar 1.23
org.slf4j : slf4j-api jar 1.7.25

test (3)

Group / Artifact Type Version
junit : junit jar 4.12
com.h2database : h2 jar 1.4.197
org.hibernate.javax.persistence : hibernate-jpa-2.1-api jar 1.0.0.Final

Project Modules

There are no modules declared in this project.

jpa-entity-generator

Build Status Maven Central

This is a Java library which generates Lombok-wired JPA entity source code. The project provides Gradle plugin and Maven plugin.

Getting Started

build.gradle

apply plugin: 'java'

buildscript {
  dependencies {
    classpath 'com.h2database:h2:1.4.197'
    classpath 'com.smartnews:jpa-entity-generator:0.99.8'
  }
}

configurations { providedCompile }
sourceSets.main.compileClasspath += configurations.providedCompile
sourceSets.test.compileClasspath += configurations.providedCompile
sourceSets.test.runtimeClasspath += configurations.providedCompile

repositories {
  mavenCentral()
}
dependencies {
  providedCompile 'org.projectlombok:lombok:1.18.2'
  providedCompile 'org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final'
}

apply plugin: 'entitygen'
entityGen {
    configPath = 'src/main/resources/entityGenConfig.yml'
}
For Maven users

Maven plugin to run the code generator is also available.

<plugin>
  <groupId>com.smartnews</groupId>
  <artifactId>maven-jpa-entity-generator-plugin</artifactId>
  <version>0.99.8</version>
  <dependencies>
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.46</version>
    </dependency>
  </dependencies>
</plugin>

Put src/main/resources/entityGenConfig.yml, and then run the following command:

mvn jpa-entity-generator:generateAll

src/main/resources/entityGenConfig.yml

jdbcSettings:
  url: "jdbc:h2:file:./db/blog;MODE=MySQL"
  username: "user"
  password: "pass"
  driverClassName: "org.h2.Driver"

packageName: "com.example.entity"

If you need more examples, check the sample entityGenConfig.yml in this repository.

entityGen task

./gradlew entityGen compileJava

entityGen task generates entity classes for all the existing tables in the database.

package com.example.entity;

import java.sql.*;
import javax.persistence.*;
import lombok.Data;

@Data
@Entity(name = "com.example.entity.Blog")
@Table(name = "blog")
public class Blog {

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Column(name = "\"id\"")
  private Integer id;
  @Column(name = "\"name\"")
  private String name;
  @Column(name = "\"active\"")
  private Byte active;
  @Column(name = "\"created_at\"")
  private Timestamp createdAt;
}

How to test on your local machine

To run the unit tests, simply run the following script as the TravisCI build does.

./test.sh

If you need to make sure if your latest code works with sample project or your existing projects, run the following command to publish the latest build to the local Maven repository.

./gradlew uploadArchives -Plocal

How to release new version

./gradlew clean uploadArchives
mvn deploy -Dmaven.test.skip=true
com.smartnews

SmartNews, Inc.

News for All

Versions

Version
0.99.8
0.99.7
0.99.6
0.99.5
0.99.4
0.99.3
0.99.2
0.99.1
0.99.0