I work with postgresql database
I have extended UniqueNumbers class, so the sequence will be saved in the additional database (not in main database) and in the schema i want.
So if i have a table with name table1 in database db1, schema name schema1, the sequence wil be saved in db1.schema1 with the name table1_id_seq.
From documentation i understand that i have to create a BeforeInsertEntityListener for every table that i have.
There is a simpler solution to achieve same result, but without create the BeforeInsertEntityListener for entity?
Thank you

1 Like

Hi Sorin,

I suppose you are working on the problem of generating identifiers for your Long/Integer-PK entities. Then you should override the cuba_NumberIdWorker bean implemented by com.haulmont.cuba.core.app.NumberIdWorker. In fact, cuba_UniqueNumbers bean is used only for application-level sequences described in the docs. The keys are assigned by a separate mechanism (though using the same approach), and you don’t need to create any entity listeners for that. Just make sure you always create instances of your entities through the Metadata interface and not by invoking constructors. See com.haulmont.cuba.core.sys.MetadataImpl#assignIdentifier for details.