From the stack trace, it looks like you have a field of type HashSet that is persistent, and the HashSet is being changed in one thread of your app, and written (PrimaryIndex.put) by another thread in your app. In other words, one HashSet instance, or the entity object that contains it, is being accessed by multiple threads, and one thread is changing it while another is reading it.
Note that this has nothing to do with database access or record locking. It only involves access to the HashSet (or entity object) instance. Normally, entity objects are not shared between threads. Are you sharing them explicitly between threads?