Finding duplicate records

Hi,

We have a class called JournalEntry with JournalEntryLine as a composition in it.We have accountCode in JournalEntryLine as an attribute. For a same journalEntry,there should not be duplicates of accountCode.How can I achieve this??

Hi,
It is achieved with a unique constraint or index.
https://doc.cuba-platform.com/manual-6.10/soft_deletion_unique_constr.html

For postgres and soft-deleted entity it will look like

create unique index IDX_xxx on yyy (JOURNAL_ENTRY_ID, ACCOUNT_CODE) where DELETE_TS is null;

Hi,
Using unique constraint is not suitable in my case because if i make the attribute unique,I cant use the same data
in other record.There should not be duplicates within a record, i.e within a JournalEntry record,there should not be duplicates of accountCode,but when we create a new journalEntry record,we should be able to use that accountCode.
Screenshot%20(377)

  I am attaching the screenshot for your reference.

That’s why you should include TWO FIELDS in the unique index, like below:

create unique index IDX_xxx on yyy (JOURNAL_ENTRY_ID, ACCOUNT_CODE) where DELETE_TS is null;

I have added it,but still facing the issue.
Screenshot%20(480)Screenshot%20(482)

If you face this exception then no doubt you have duplicates of (journal entry, account code) pair in the database.