Changing userId (username) by code

Showing results for 
Search instead for 
Did you mean: 
Member II

Changing userId (username) by code

Hi all, I'm interacting with Activiti by using the Activiti Engine 5.20 API.

Is it possible to change the userID (and the groupId) through indentyService?
        IdentityService identityService = processEngine.getIdentityService();
        org.activiti.engine.identity.User identiUser = identityService.createUserQuery().userId("kermit").singleResult();

It throws

org.activiti.engine.ActivitiOptimisticLockingException: org.activiti.engine.impl.persistence.entity.UserEntity@650ae78c was updated by another transaction concurrently
    at org.activiti.engine.impl.db.DbSqlSession.flushUpdates(
    at org.activiti.engine.impl.db.DbSqlSession.flush(
    at org.activiti.engine.impl.interceptor.CommandContext.flushSessions(
    at org.activiti.engine.impl.interceptor.CommandContext.close(
    at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(
    at org.activiti.engine.impl.interceptor.LogInterceptor.execute(
    at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(
    at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(
    at org.activiti.engine.impl.IdentityServiceImpl.saveUser(
    at com.jnsw.gesdoc.test.ActivitiUnitTest.updateUserID(

(I think we cannot change userId because it is a key and it cannot retrieve anylong identiUser beacause we've changed the id)

Thanks in advance.

1 Reply
Established Member II

Re: Changing userId (username) by code


My results are consistent with yours; I'm not sure if there is a workaround for this.
In all cases that I've found or that have worked for me, the 'setId' method is only usable for preemptive setting of a user's ID value - not changing it after it's been saved already.