Hello, I've the following situation which indeed drives me crazy, cause I cannot find a solution for it.
I have an entity called Person that has a OneToMany-Relationship with CascadeType.ALL and orphanRemoval to an entity called Lock. This allows the user to place a lock on certain information for the person defined by the Lock entity via a manually generated Primary Key (LockPK). Before a person tries to lock anything, we do a refresh on the Person to make sure, the locks are correct. Now see the following situation: User A and User B both open the application. User A applies a Lock on the Person for a specific information. The database correctly contains the lock. User B tries to apply the Lock too, but gets an error, that User A is already working with the information. User A removes the Lock by simply removing it from the list within the Person. The database is correctly updated, the lock is removed. If now, User B refreshes the information from Person, this leads to the following exception: Caused by: <openjpa-2.2.3-SNAPSHOT-r422266:1564471 nonfatal store error> org.apache.openjpa.persistence.EntityNotFoundException: Die folgenden Instanzen sind nicht im Datenspeicher vorhanden: [com.daimler.mbbank.rating.db.entity.Lock-com.daimler.mbbank.rating.db.entity.LockPK@80b44e2e [org.apache.openjpa.util.ObjectId]] at org.apache.openjpa.kernel.BrokerImpl.newObjectNotFoundException(BrokerImpl.java:4735) at org.apache.openjpa.kernel.BrokerImpl.refreshInternal(BrokerImpl.java:3084) ... 93 more Caused by: <openjpa-2.2.3-SNAPSHOT-r422266:1564471 nonfatal store error> org.apache.openjpa.persistence.EntityNotFoundException: Die Instanz "com.daimler.mbbank.rating.db.entity.Lock-com.daimler.mbbank.rating.db.entity.LockPK@80b44e2e [org.apache.openjpa.util.ObjectId]" ist nicht im Datenspeicher vorhanden. FailedObject: com.daimler.mbbank.rating.db.entity.LockPK@d33d3a8 at org.apache.openjpa.kernel.BrokerImpl.newObjectNotFoundException(BrokerImpl.java:4734) ... 94 more By simply refreshing a second time, we overcome this problem, as OpenJPA does not refresh missing instances again. User B now does not see a lock and therefore tries to lock the Person itself. This however, leads to the following exception: [err] <openjpa-2.2.3-SNAPSHOT-r422266:1564471 fatal store error> org.apache.openjpa.persistence.EntityExistsException: Es ist bereits ein Objekt des Typs "com.daimler.mbbank.rating.db.entity.Lock" mit der OID "com.daimler.mbbank.rating.db.entity.Lock-com.daimler.mbbank.rating.db.entity.LockPK@80b44e2e" in diesem Kontext vorhanden. Es kann kein weiteres Objekt persistent gespeichert werden. FailedObject: com.daimler.mbbank.rating.db.entity.Lock@2b9f8c2e Nice, even though OpenJPA told us before, the object is no longer existing, it still keeps in the context. what am I supposed to do here? Ok I thought, I'd try to FIND it via EntityManager.find(). However, that gets me to the next exception: <openjpa-2.2.3-SNAPSHOT-r422266:1564471 nonfatal store error> org.apache.openjpa.persistence.EntityNotFoundException: Die Instanz des Typs "class com.daimler.mbbank.rating.db.entity.Lock" mit der OID "com.daimler.mbbank.rating.db.entity.Lock-com.daimler.mbbank.rating.db.entity.LockPK@80b44e2e" ist nicht mehr im Datenspeicher vorhanden.Dies kann bedeuten, dass Sie die Instanz in einer gesonderten Transaktion gelöscht haben, aber noch eine Version dieses Kontextes im Cache vorhanden ist. FailedObject: com.daimler.mbbank.rating.db.entity.Lock-com.daimler.mbbank.rating.db.entity.LockPK@80b44e2e OpenJPA complains, that the Lock has been removed by a different transaction. YES THAT IS CORRECT. But what shall I do now? I can't update, nor merge, nor find again. Nothing works here, I always get the exception that there is either something existing in the cache/context that is actually no longer in the Database OR something no longer in the database. Can somebody please explain to me, what I'm supposed to do to handle such a situation of two users modifying the very same list while in between not closing the entity manager? The following questions arise to me here: OpenJPA tells me, that when refreshing an entity (Person), a associated entity (Lock) is gone. A second refresh does not contain the gone entity -> Fine. But why still keep it in the cache? OpenJPA tells me, that there is already an entity with a certain PK in the context, a new one cannot be persisted. But it is not persisted, its simply in the context, how to get rid of it? OpenJPA tells me, that the object has been removed, but the cache still contains it. Okay fine, but WHAT am I supposed to do here? I'm a little bit flabbergasted about all this. Was it intentional to make working with Entities, NOT the entity manager or queries that complicated? Curious, if somebody can help me fix this. And PS: Updating OpenJPA is NOT an option. We need to stick with the version provided by WebSphere Application Server. However, if there seems to be a bug, I can open a PMR to make WebSphere fix it. Thank you for your help, Heiko -- View this message in context: http://openjpa.208410.n2.nabble.com/org-apache-openjpa-persistence-EntityNotFoundException-The-instance-of-type-class-com-test-testapp-m-tp7586840.html Sent from the OpenJPA Users mailing list archive at Nabble.com.