Faker Doesn't Know Your Entities Are Related, So I Built Something That Does
Faker Doesn't Know Your Entities Are Related, So I Built Something That Does You've added a second entity to the schema, wired up a @ManyToOne , and gone back to your seed script to generate fifty more rows. Ninety seconds later, the app refuses to start: unique constraint violation, somewhere inside a loop you wrote three weeks ago at 11pm. You fix it. You restart. A different field breaks a…
Faker libraries are great for generating names, emails, and addresses, but they fall short when dealing with complex relationships between entities. When you add a second entity to your schema and try to generate data using Faker, you may encounter unique constraint violations in your seed script. This happens because Faker doesn't understand the relationships between your entities, resulting in a need for manual wiring and debugging.
Enter SynthForge, a tool that uses JPA-managed attributes to seed your database correctly. Instead of writing separate generation scripts, you simply annotate your entities with the @Seed annotation, specifying the desired count for each entity. SynthForge reads the JPA-managed attributes through the jakarta.persistence.metamodel.Metamodel API, which allows it to focus only on real persistent fields and build a dependency graph for relationship ordering.
This ensures that parent rows are created before child rows, preventing unique constraint violations.
Furthermore, SynthForge is capable of handling field-level constraints like @NotNull, @Size, @Email, and even heuristics for common data types such as emails, IBANs, amounts, and countries. It generates realistic values based on these constraints, avoiding constraint violations that often occur in manual seed scripts.
The main difference between SynthForge and Instancio lies in their usage scenarios. While Instancio provides an API for generating data within a test method, SynthForge automatically populates the database during application startup. This means that SynthForge handles the seeding process in the background, allowing developers to focus on their application's core functionality.
SynthForge is available on Maven Central, with the dependency listed as `io.github.thembatman0:synthforge-spring:0.1.0`. It won't change your architecture or make decisions for you, but it can certainly save you time and frustration when dealing with complex entity relationships during your application's development and startup process.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.