Native Databases with Foreign Key Constraints
Use
The SAP implementation of JPA does not require foreign key constraints on the database. Moreover, when you use the system database to store your application tables, you create the tables in the Java Dictionary and you use Open SQL connections to deploy them on the database. In this case you do not have foreign key constraints on the table definitions.
However, if you have a native database schema that imposes foreign key constraints, the JPA implementation has to sort the executed SQL statements in a way to avoid foreign key violations. You can enable this feature via the com.sap.jpa.execution.foreign-key-handling property and its value topological in the persistence.xml file.
More information: persistence.xml
JPA works with foreign key constraints on the database for the following scenarios:
-
Relationships without join-tables (one-to-one, many-to-one) - one foreign key constraint defined on the table of the entity that is the owning side of the relationship referring to the primary key of the table of the target entity
-
Relationships with join-tables (unidirectional one-to-many, many-to-many) - two foreign key constraints defined on the common join-table referring to the primary keys of the tables of the related entities
-
Secondary tables - one foreign key constraint defined on each secondary table referring to the primary key of the primary table
-
Inheritance - one foreign key constraint defined on each subclass table referring to the primary key of the superclass table
<property name = "com.sap.jpa.execution.foreign-key-handling" value = "topological"/>