Skip to content

Tutorial 5: (Configuration) Adding Preconditions

Kumar Rohit edited this page Oct 3, 2015 · 1 revision

Adding Preconditions

You have two independent tables having no relationship between them, but you still want to create them in specific orders. To enforce order during the creation you can add preconditions to jpa context factory.

Let us say you want Account entity to be created before Person entity, although Person doesn't have a direct relationship with Account

final JPAContextFactory jpaContextFactory 
    = JPAContextFactory.newInstance(Database.MY_SQL, persistenceService.getEntityManager());

jpaContextFactory.withPreconditions(Before.of(Person.class).create(Account.class));

Note: This is a system level configuration, Random-JPA would try to adjust order but skips if it's in direct conflict with foreign key relationship

Clone this wiki locally