openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From areider <>
Subject Re: Delete OptimisticLock exception, when entity appears 2x in cascade graph
Date Fri, 14 Oct 2011 05:08:35 GMT
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" 

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

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

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:
Sent from the OpenJPA Users mailing list archive at

View raw message