Skip to content


Tobias Liefke edited this page May 14, 2020 · 15 revisions

First steps with Fastnate

Fastnate currently provides three different parts:

  • The generator itself in fastnate-generator, which takes any JPA annotated entities and generates a SQL file on the fly. Use this one if you want to have full control over the generated SQL file or if you have really a big amount of data that you want to import. We call that the push API, as you have to push your data into Fastnate.
  • The entity importer in fastnate-data, which finds all creators of entities automatically, collects all data and writes the SQL file in the end. Use this if the amount of created entities is small enough to fit into memory at ones and if you would like to start immediately. Thats why we will demonstrate that one first. We call this the pull API, as it asks every provider for the data.
  • Last but not least we've got the fastnate-maven-plugin, which makes it easy to use the entity importer in Maven or Eclipse.

This page will show you a short introduction for using fastnate-data and fastnate-maven-plugin.

Before we can start

We assume that you've got a JPA project already. If you don't - you could use fastnate-examples as blueprint. But remember that this one contains most of the steps already which we will do in the following chapters.

We are using Lombok for generating obvious code snippets like getters, setters and constructors. Even if you don't know Lombok (until now), the used annotations should be self explaining - and you can look up any of them in the feature overview of Lombok. You can replace the annotations with Delombok if you feel that it helps to understand the code.

1. Attach Fastnate to your compile path

Either download and add fastnate-data and fastnate-generator manually or attach fastnate-data to your Maven project - both is described on our download page.

Here is the example of embedding it in your Maven pom.xml:


2. Define your entity classes

If you haven't created an entity class up to now, here is an example:


public class Person {

	private Long id;

	private String firstName;

	private String lastName;

	public Person(final String firstName, final String lastName) {
		this.firstName = firstName;
		this.lastName = lastName;

3. Build your test data

Implement and create you example entities:


public class PersonData extends AbstractDataProvider {

	private final List<Person> entities = new ArrayList<>();

	public void buildEntities() throws IOException {
		this.entities.add(new Person("Nate", "Smith"));
		this.entities.add(new Person("Natalie", "Smith"));

4. Start the generation

Run Either with a "hand made" classpath or with Maven:


Further configuration parameters can be found in the documentation of the maven plugin.

Please note that the plugin is bound to the process-classes phase, because Fastnate needs the compiled classes to run. So mvn compile won't trigger the generation, while mvn process-classes or any later phase like mvn test or mvn package will do. You can even invoke the plugin directly (if your classes are already compiled) with mvn org.fastnate:fastnate-maven-plugin:import-data.

5. Finished

If everything succeeds you will find a new file data.sql - either in your target/classes directory (in Maven) or in your working directory (if you started the EntityImporter manually):

INSERT INTO Person (firstName, lastName) VALUES ('Nate', 'Smith');
INSERT INTO Person (firstName, lastName) VALUES ('Natalie', 'Smith'); 

To go on further read the How-tos or FAQs.