Cascade persist behavior
In previous releases, OpenJPA would check the database for the existence of the related Entity before persisting the relationship to that Entity.
This resulted in an extra Select being sent to the database.
In 2.2.0, code was added so that when cascading a persist to a related Entity without persistence state, the persist (insert) will happen without first checking the database.
This may result in an EntityExistsException if the related Entity already exists in the database.
To revert this behavior to the previous release, set the value of the openjpa.Compatibility property CheckDatabaseForCascadePersistToDetachedEntity to true.
This property does not cover a relation without cascade that refers to a manageable instance which has no persistence state in the current context, for example an entity of a runtime enhanced (subclassed) type that was detached when a previous transaction committed.
Such an instance is looked up in the database irrespective of the value of CheckDatabaseForCascadePersistToDetachedEntity, because the lookup is the only available evidence that the instance was persisted before.
The lookup is skipped if the primary key values of the instance show that it never was assigned an identity; the relation is then reported as a reference to an unmanaged instance.