LazyInitilization Exception when tried to Get profiles from Bundle

Hi,

can someone help me on the below error, so actually error is coming in script in Workflows when i try to get Profiles from assigned Role..

Caused by: org.apache.bsf.BSFException: The application script threw an exception: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: sailpoint.object.Bundle.profiles, could not initialize proxy - no Session BSF info: script at line: 0 column: columnNo

Thanks
Prashanth

Can you share the piece of code where it is throwing this error . so we can analyze .

Also check that you are decaching something or passing the full object .

HI harsha,

below is the piece of code, where I am trying to get Profiles from assigned roles

	if ((assignedRoles != null) && (assignedRoles.size() > 0)) {
    log.debug("Checking Roles for entitlements");
    for (Bundle assignedRole: assignedRoles) {
    log.debug(" Step :--- calcute plan ------ -  AssignedRole "+assignedRole.getName());
		String bundleDesc = assignedRole.getDescription("en_US");
     log.debug(" Step :--- calcute plan ------  "+bundleDesc);
		if( bundleDesc != null && bundleDesc.contains(AppName)){
			getAcc = true;
			log.debug(" Step :--- calcute plan ------ ");
			//noRoleDesc = false;
		}
		if(!getAcc){
			
			SpecificProfiles = assignedRole.getProfilesForApplications(new ArrayList(Arrays.asList(AppName)));
   	log.debug(" Step :--- calcute plan ------ getProfiles method "+SpecificProfiles);
			if(!Util.isEmpty(SpecificProfiles)){
				getAcc = true;
			}
		}
     
	  if(!getAcc){
      List requiredRoles = assignedRole.getRequirements();
    log.debug(" Step :--- calcute plan ------ getRequirements "+SpecificProfiles);
      if (requiredRoles != null && requiredRoles.size()>0) {
       for (Bundle requiredRole: requiredRoles) {
		//requiredRole.load();
          if (requiredRole.getName().equals("AccShellAccount")) {
            getAcc = true;
            log.debug("No entitlements found on role but user is indicated for shell account. getAcc set to true.");
          }
        }
      }
	 }
	 if(getAcc)
	 break;
    }
  }

thanks
Prashanth

Hello @PrashRV

From the code you shared, it seems to me that the assignedRole might be detached from Hibernate session, and therefore accesing its fields like profiles will throw LazyInitializationException. Please try to reload the assignedRole object from the database using context to ensure it’s fully attached to the session.

for (Bundle assignedRole : assignedRoles) {
    log.debug(" Step :--- calcute plan ------ -  AssignedRole " + assignedRole.getName());

    // Re-fetch role using id or name to ensure it's attached to the Hibernate session
    assignedRole = context.getObjectById(Bundle.class, assignedRole.getId());

    String bundleDesc = assignedRole.getDescription("en_US");
            //your code...
}

Thanks @PrashRV . Can you try to reload assignedRole object and see if its fixed the issue . And from the logs are you able to check where exactly is it failing .

Thanks Animesh, tried as you suggested
its working now.

Thanks Harsha for the reply,