Is there a way to extend the Hibernate Entity Manager?


I am using hibernate OGM JPA with MongoDB. The problem I am trying to solve is adding operation retry logic to the find, persist, query, remove methods in a JPA environment. The underlying data source driver is the mongodb driver. We are experiencing the driver throwing network exceptions if we are connected to the primary member of replica set and that primary goes down. We need to retry the operation when our applications get a network exception, however, I want to be able to make this retry logic part of the EntityManager so all of our applications will not have to incorporate this boiler plate code. I have not seen anything that specifically says that extending the Hibernate Entity Manager is possible. The hibernate bootstrap process seems like it may allow me to do this, however, I am not sure. Can anyone tell me if this is possible and guide me to some resources/examples that I can look at?