How to control the order in which JPA entities are created on Spring Boot App initialization?

Viewed 70

How to control the order in which JPA entities are created on Spring Boot App initialization, when we use H2 or MySQL sometimes we feel the child table is created prior to the parent table. In such a scenario schema creation fails causing application to not startup

1 Answers

I think you are talking about a liquibase like framework, In that case you will need to manually order if for example A has a foreign key referring from table B, then table A needs to be created before B. Unless this there is no issue coming from JPA or Spring Boot because entity classes get linked with annotation correctly so when they are called necessary proxy classes get created and linked accordingly.

Related