-
Notifications
You must be signed in to change notification settings - Fork 4
Tutorial 2: (Configuration) Adding Custom Dependency
Kumar Rohit edited this page Oct 2, 2015
·
1 revision
There are many systems which doesn't have proper foreign key relationship. In order to create relationship with other entities, random-jpa provides dependencies to be added to JPAContextFactory. Based on these provided custom dependencies and foreign key relationship, a JPAContext is created.
Let us say that you want have a custom dependency between Person and Employee tables but you do not have any foreign key relationship between them. We will have create Dependencies for this using javax.persistence.metamodel.Attribute objects. (Here Person_ & Employee_ are SingularAttributes)
final Dependencies dependencies = Dependencies.newInstance();
dependencies.withLink(Link.newLink(Employee_.personId, Person_.id));
JPAContext jpaContext = JPAContextFactory.newInstance(Database.ORACLE, entityManager)
.with(dependencies)
.create();
Represents, Employee's personId has a foreign key relation to Person's id.