protected Object resolveIdIfEntity(Object value) { // use the object id as the value if its a persistent entity MappingContext mappingContext = entity.getMappingContext(); if (mappingContext.getProxyFactory().isProxy(value)) { return mappingContext.getProxyFactory().getIdentifier(value); } return mappingContext.isPersistentEntity(value) ? findInstanceId(value) : value; }