I made some changes to tell OpenJPA to observe foreign key constraints. I didn't do it with SynchronizeMappings because it is not crystal clear to me exactly under what circumstances the MappingTool might ever make attempt to make changes to the database. (I am in a strictly 'bottom-up' environment).
Instead, I added <property name="openjpa.jdbc.MappingDefaults" value="jpa(ForeignKeyDeleteAction=restrict,JoinForeignKeyDeleteAction=restrict)"/> to persistence.xml which I believe tells OpenJPA to treat all relationships as if they are based on foreign keys. Is this equivalent? I got the same error as before. In the (very voluminous) OpenJPA walkback (too many printStackTrace()s?) I actually see 2 different errors, an RI error, and the optimistic lock error. I'm not sure which one is the root error. But judging by the @preremove and @postremove calls ahead of the error (if in fact the order of those callbacks reflects the batch order), it does appear that the deletes are in fact being done in an order that is respecting the constraints, but some entities appear to be getting deleted more than once. In the actual object graph, some Employees have more than one instance, eg the Joe employee under the department as well as under the JoesBoss employee. So could this be a problem that is specific to having entities with multiple foreign keys pointing to other entities within the in the same graph that is being deleted and thus occuring more than once in the graph, rather than a problem with the sort? I have other serious issues with this model, because in reality, the entity i'm calling an Employee itself has a very large subgraph under it, and it is obviously inefficient for it to be repeated in the object graph as equal (but not identical) objects. So at best, this structure is not very nicely mapped to objects at all. Nevertheless, our data modelers insist this is a very common and frequent pattern, and must be supported as is by the ORM. -- View this message in context: http://openjpa.208410.n2.nabble.com/Delete-OptimisticLock-exception-when-entity-appears-2x-in-cascade-graph-tp6882907p6891334.html Sent from the OpenJPA Users mailing list archive at Nabble.com.