Unable to re-create user after deleting

We have a business requirement where we need to delete a user entity, and re-create it again in KeyCloak.
This is the code to remove the user.

UserModel user = session.users().getUserByEmail(email,session.getContext().getRealm());
session.users().removeUser(session.getContext().getRealm(), user);

And then create:

UsersResource usersRessource = realmResource.users();
 UserRepresentation user = new UserRepresentation();
//populate user representation object here
...
Response response = usersRessource.create(user);

At this point we get an exception:

2021-02-11 17:49:29,852 ERROR [org.keycloak.services.error.KeycloakErrorHandler] (default task-14) Uncaught server error: javax.persistence.PessimisticLockException: could not execute statement
                at org.hibernate.internal.ExceptionConverterImpl.wrapLockException(ExceptionConverterImpl.java:273)
                at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:108)
                at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:181)
                at org.hibernate.query.internal.AbstractProducedQuery.executeUpdate(AbstractProducedQuery.java:1594)
                at org.keycloak.models.jpa.JpaUserProvider.removeUser(JpaUserProvider.java:143)
                at org.keycloak.models.jpa.JpaUserProvider.removeUser(JpaUserProvider.java:137)
                at org.keycloak.models.UserManager.removeUser(UserManager.java:36)
                at org.keycloak.storage.UserStorageManager$2.run(UserStorageManager.java:356)
                at org.keycloak.models.utils.KeycloakModelUtils.runJobInTransaction(KeycloakModelUtils.java:227)
                at org.keycloak.storage.UserStorageManager.deleteInvalidUser(UserStorageManager.java:348)
                at org.keycloak.storage.UserStorageManager.importValidation(UserStorageManager.java:324)
                at org.keycloak.storage.UserStorageManager.getUserByUsername(UserStorageManager.java:402)
                at org.keycloak.models.cache.infinispan.UserCacheSession.getUserByUsername(UserCacheSession.java:257)
                at org.keycloak.services.resources.admin.UsersResource.createUser(UsersResource.java:121)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

Is it because we are using the UserModel in the session to delete, but using the Realm UserResource to create?