code: private static org.hibernate.engine.spi.EntityKey getOptionalObjectKey(QueryParameters queryParameters, SharedSessionContractImplementor session) {
  		final Object optionalObject = queryParameters.getOptionalObject();
  		final Serializable optionalId = queryParameters.getOptionalId();
  		final String optionalEntityName = queryParameters.getOptionalEntityName();
  
  		if ( optionalObject != null && optionalEntityName != null ) {
  			return session.generateEntityKey( optionalId, session.getEntityPersister( optionalEntityName, optionalObject ) );
  		}
  		else {
  			return null;
  		}
  	}
docs: Copied from Loader#getOptionalObjectKey