Hibernate error while filtering Link attributes using QueryOptions

Hi everyone,

I am encountering a persistent Hibernate error when attempting to search for specific accounts using

Error Message : Cannot invoke “org.hibernate.hql.internal.ast.tree.FromElement.setAllPropertyFetch(boolean)” because “fromElement” is null

Below is the code where I am getting error

import sailpoint.object.Link;
import sailpoint.object.Filter;
import sailpoint.object.QueryOptions;
import java.util.Iterator;

QueryOptions qo = new QueryOptions();
qo.addFilter(Filter.eq(“application.name”, “AD”));
qo.addFilter(Filter.eq(“attributes.SAMACCOUNTNAME”, “1a2a3c”)); // Tried using links.attributes
qo.addFilter(Filter.eq(“attributes.Disabled”, false));

Iterator it = context.search(Link.class, qo);
while (it.hasNext()) {
Link link = (Link) it.next();
Identity id = link.getIdentity();
if (id == null || Boolean.TRUE.equals(id.isDisabled())) {
continue;
}
String displayName = (String) link.getAttribute(“displayName”);
String apmNumber  = (String) link.getAttribute(“apmNumber”);

}

I am querying Link.class and filtering on application name and link attributes.
Is this the correct way to construct the filters, or do I need to change anything to avoid this Hibernate error?

Any guidance would be appreciated.

@SDM007

Can you tell me what you need as your end result?

Do you need to fetch the Link attribute details for a user from a certain application ?

Utilize this code if you are fetching link attribute details for a user and a certian application.

***
	 * This Method is used to fetch the link attributes of a particular Application and a user.
	 * @param userId
	 * @param appName
	 * @return
	 */
	public Map<Object, Object> getLinkAttributeMap(String userId, String appName) {
		Map linkAttr = new HashMap<Object, Object>();
		
		if(Util.isNotNullOrEmpty(userId) && Util.isNotNullOrEmpty(appName)) {
			try {
				Filter filter = Filter.and(Filter.eq("application.name", appName), Filter.eq("identity.name", userId));
				QueryOptions queryOptions = new QueryOptions();
				
				queryOptions.addFilter(filter);
				Attributes attrs = null;
				
				Iterator<Object[]> iteratorSearch = context.search(Link.class, queryOptions, "attributes");
				
				if(null != iteratorSearch) {
					if(iteratorSearch.hasNext()) {
						attrs = (Attributes) iteratorSearch.next()[0];
					}
					
					if(null != attrs) {
						linkAttr = attrs;	
					}
					
					Util.flushIterator(iteratorSearch);
				}
				
			}catch(Exception exp) {
				System.out.println("Exception occurred while fecthing link Attributes:- " + exp.getMessage());
			}
		}
		return linkAttr;
	}

Hi @SDM007,

Hope you are doing great.

I don’t believe we can filter the link attributes directly from QueryOptions.

Probably thats why you are receiving this error.

Please try something like this:

        QueryOptions qo = new QueryOptions();
        List andFilter= new ArrayList();
        andFilter.add(Filter.eq("application.name", "ADName"));
        andFilter.add(Filter.like("nativeIdentity", "CN=..., Filter.MatchMode.START));
        qo.addFilter(Filter.and(andFilter));
        
        Iterator it = context.search(Link.class, qo);

Than, during the code you can check if the link.isDisable().

Hope it helps.

@SDM007

You can use below working code.

QueryOptions qo = new QueryOptions();
List andFilter= new ArrayList();
Filter.add(Filter.eq("application.name",appName));
Filter.like("identity", "CN=" + wantedCN, Filter.MatchMode.START);
qo.addFilter(Filter.and(andFilter));

Iterator itx = context.search(Link.class, qo);

Please refer below link.