0

I have Java Spring project which is using CrudRepository for the entities in the DB (postgresql).

I need to have a quick way to use the entities definitions in order to create the DB tables and constraints, I don't want to use SQL queries to do that, or Java code.

Also, I want to create a populator for these entities with fake data, using maven plugin.

I was looking in the WEB to find best practices to reach above functionality and I couldn't find.

1
  • Did you see Liquibase: liquibase.org Commented Mar 23, 2020 at 14:22

1 Answer 1

2

To create the database schema from the entities' definition, you can use the property spring.jpa.hibernate.ddl-auto.

And for the data initialization, you can create a data.sql script at your resources, and it will run on the application initialization.

You can read more about it at the docs.

For a more fine-grained solution, you can use tools like Liquibase and Flyway.

Sign up to request clarification or add additional context in comments.

1 Comment

For me data.sql is not read when spring.jpa.hibernate.ddl-auto is not none. It is only read when spring.jpa.hibernate.ddl-auto is none so the schema needs to exist. Any idea ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.