private Entity getRandomEntity(final String pluginIdentifier, final String modelName) {
   SearchCriteriaBuilder searchBuilder =
       dataDefinitionService.get(pluginIdentifier, modelName).find();
   int totalNumberOfEntities = searchBuilder.list().getTotalNumberOfEntities();
   return searchBuilder
       .setMaxResults(1)
       .setFirstResult(RANDOM.nextInt(totalNumberOfEntities))
       .uniqueResult();
 }
  @Override
  public long count(final SearchCriterion criterion) {
    final String countAlias = "count";
    SearchCriteriaBuilder scb = find();
    if (criterion != null) {
      scb.add(criterion);
    }
    scb.setProjection(alias(rowCount(), countAlias));
    scb.addOrder(asc(countAlias));

    Entity countProjection = scb.setMaxResults(1).uniqueResult();
    return (Long) countProjection.getField(countAlias);
  }
 protected String getRandomDictionaryItem(final String dictionaryName) {
   Entity dictionary = getDictionaryByName(dictionaryName);
   SearchCriteriaBuilder searchBuilder =
       dataDefinitionService
           .get("qcadooModel", "dictionaryItem")
           .find()
           .add(SearchRestrictions.belongsTo("dictionary", dictionary));
   int total = searchBuilder.list().getTotalNumberOfEntities();
   return searchBuilder
       .setMaxResults(1)
       .setFirstResult(RANDOM.nextInt(total))
       .uniqueResult()
       .getField(NAME)
       .toString();
 }