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

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



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1