private void addSampleCodeCriterion(Criteria criteria, String sampleCode) {
   String[] sampleCodeTokens =
       sampleCode.split(SampleIdentifier.CONTAINED_SAMPLE_CODE_SEPARARTOR_STRING);
   if (sampleCodeTokens.length > 1) {
     final String containerCode = sampleCodeTokens[0];
     final String code = sampleCodeTokens[1];
     criteria.add(Restrictions.eq("code", CodeConverter.tryToDatabase(code)));
     criteria.createAlias("container", "c");
     criteria.add(Restrictions.eq("c.code", CodeConverter.tryToDatabase(containerCode)));
   } else {
     criteria.add(Restrictions.eq("code", CodeConverter.tryToDatabase(sampleCode)));
     criteria.add(Restrictions.isNull("container"));
   }
 }
  // LockSampleModificationsInterceptor automatically obtains lock
  private final void internalCreateSample(
      final SamplePE sample,
      final HibernateTemplate hibernateTemplate,
      final ClassValidator<SamplePE> classValidator,
      final boolean doLog) {
    validatePE(sample, classValidator);
    sample.setCode(CodeConverter.tryToDatabase(sample.getCode()));

    hibernateTemplate.saveOrUpdate(sample);
    if (doLog && operationLog.isInfoEnabled()) {
      operationLog.info(String.format("ADD: sample '%s'.", sample));
    }
  }
  private List<SamplePE> listByPropertyValue(
      String queryFormat, String propertyCode, String propertyValue, GroupPE parent) {
    String simplePropertyCode = CodeConverter.tryToDatabase(propertyCode);
    boolean isInternalNamespace = CodeConverter.isInternalNamespace(propertyCode);
    Object[] arguments = toArray(propertyValue, parent, simplePropertyCode, isInternalNamespace);

    String queryPropertySimpleValue = String.format(queryFormat, "value");
    List<SamplePropertyPE> properties1 =
        cast(getHibernateTemplate().find(queryPropertySimpleValue, arguments));

    String queryPropertyVocabularyTerm = String.format(queryFormat, "vocabularyTerm.code");
    List<SamplePropertyPE> properties2 =
        cast(getHibernateTemplate().find(queryPropertyVocabularyTerm, arguments));

    properties1.addAll(properties2);
    List<SamplePE> entities = extractEntities(properties1);
    return entities;
  }