Failed to lazily initialize a collection of role assignedRole

hi everyone,

I’m trying to use an async function to reduce the response time, but when I try to execute, i get the following error: “failed to lazily initialize a collection of role: sailpoint.object.Identity.assignedRoles, could not initialize proxy - no Session

my code is doing something like:

List<Bundle> bundles = identity.getBundles(app);
List<Bundle> assignedRoles = identity.getAssignedRoles();
List<Bundle> bundlesComClassificaoExistente = new ArrayList<Bundle>();
        
CompletableFuture<Void> backgroundTask = CompletableFuture.runAsync(() -> {
            try {
                Boolean possuiClassificacao = false;
					for(Bundle b : bundles) {
						List<ObjectClassification> classificationsBundle = b.getClassifications();
						for(ObjectClassification classification : classificationsBundle) {
							if(classification.getClassification().getName().equals(classif)) {
								possuiClassificacao = true;
								bundlesComClassificaoExistente.add(b);
							}
						}
					}
					for(Bundle b : assignedRoles) {
						List<ObjectClassification> classificationsBundle = b.getClassifications();
						for(ObjectClassification classification : classificationsBundle) {
						if(classification.getClassification().getName().equals(classif)) {
							possuiClassificacao = true;
							bundlesComClassificaoExistente.add(b);
						}
					}
				}
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });

what can be wrong with assignedRoles variable? the bundles variable is running ok

@cris1 are u passing identity object or every time you are creating object ?

i prefer to get object each time and decache it once done. also Bundle b should be fine becoz it’s inside for loop. try to comment 2nd for loop and see if problem still persists.

context.getObject(Identity.class, identityName);

if you can share complete code then it would be great.

i’m using just one identity object.

i commented the 2nd for loop and it worked without any problem, the real problem its the method getAssignedRoles inside the async function (without async the 2nd for loop worked)

try

b.getClassifications() by creating a Transactional method.

the only way i found to solve this problem was not use async function

1 Like

Hi @cris1 , try calling identity.loadForProvisioning() to force the assignedRoles to be fully loaded