diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/api/v1/GeneralInformationService.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/api/v1/GeneralInformationService.java index 6f4b5af455af778d6c221c1dbf0e38910829b0c0..b3a318f12a78e7f3cbc454c47fd97c02414a3666 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/api/v1/GeneralInformationService.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/api/v1/GeneralInformationService.java @@ -1388,8 +1388,14 @@ public class GeneralInformationService extends AbstractServer<IGeneralInformatio querySampleTypeId.setParameter("sampleTypeCode", sampleTypeCode); int sampleTypeId = ((Number) querySampleTypeId.uniqueResult()).intValue(); - SQLQuery querySampleCount = currentSession.createSQLQuery("SELECT COUNT(*) FROM samples_all WHERE saty_id = :sampleTypeId"); + SQLQuery querySampleTypePrefix = currentSession.createSQLQuery("SELECT generated_code_prefix from sample_types WHERE code = :sampleTypeCode"); + querySampleTypePrefix.setParameter("sampleTypeCode", sampleTypeCode); + String sampleTypePrefix = ((String) querySampleTypePrefix.uniqueResult()); + + SQLQuery querySampleCount = + currentSession.createSQLQuery("SELECT COUNT(*) FROM samples_all WHERE saty_id = :sampleTypeId AND code ~ :codePattern"); querySampleCount.setParameter("sampleTypeId", sampleTypeId); + querySampleCount.setParameter("codePattern", "^" + sampleTypePrefix + "[0-9]+$"); long sampleCount = ((Number) querySampleCount.uniqueResult()).longValue(); return sampleCount;